#clojure log - Jul 04 2010

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:01 polypus: hello bahman

0:02 is there a built in function for getting the index of the first value in a sequence for which some predicate is true?

0:02 unlink: Is this not supposed to work? (defprotocol P (f [x]) (f [x y]))

0:03 Not saying it's a good idea, I am just trying to reify an interface that looks something like that.

0:12 mudgen: hello

0:12 does anybody know how to get clojure classloaders to work with java webstart?

0:13 I wrote a clojure program that is launched with java webstart, but the clojure classloaders doen't seem to be working

0:16 is this not a good time to ask questions?

0:16 Blackfoot: usually people are pretty helpful, but perhaps no one else is around.

0:17 and i haven't used webstart, sorry

0:24 mudgen: can someone tell me what clojure.lang.RT is?

0:26 unlink: mudgen: The Clojure runtime.

0:26 mudgen: thanks

0:27 i am getting this error from a java webstart program that tries to load my clojure classes: java.io.FileNotFoundException: Could not locate clojure/core__init.class or clojure/core.clj on classpath:

0:27 unlink: Man, the Java library I am using is just so stateful, I'm not sure even makes sense to attempt to use Clojure here.

0:27 mudgen: anybody know what is causing that error?

0:29 mikem: mudgen: looks like the classpath :)

0:29 mudgen: did you aot compile your clojure code?

0:30 mudgen: mikem, yes, it is AOT

0:31 rhudson: unlink: syntax for that is (defprotocol P (f [x] [x y]))

0:32 mudgen: mkiem: it isn't a problem with the classpath, because the program finds clojure.jar just finds and starts to run my clojure program, it's that the clojure itself cannot find its own classes

0:32 just fine*

0:32 the clojure classloaders aren't working or something

0:32 mikem: mudgen: hm, not sure :S

0:38 Bahman: mudge: http://groups.google.com.sg/group/clojure/browse_thread/thread/f0c69735c5a9bd03/1e0dced366af9077?lnk=gst&q=webstart&fwc=1

0:38 mudgen: http://groups.google.com.sg/group/clojure/browse_thread/thread/f0c69735c5a9bd03/1e0dced366af9077?lnk=gst&q=webstart&fwc=1

0:39 mudge: Sorry...typing mistake.

0:39 mudgen: checking it out

0:48 bortreb: polypus: swank.util/position does exactly what you want

0:50 polypus: if you don't like swank you can just take the first value of clojure.contrib.seq-utils/positions

0:53 I'm having a lot of trouble integrating clojure with my team's java project -- I want to rewrite a few .java source files with better clojure versions, but I can't figure out how to compile the whole thing, s

0:54 since some java files depend on the newly written clj file, but the clj files depends on other (different) java files

0:54 right now I'm just using a script to compile them in the right order

0:54 but is there a better , standard way?

0:55 polypus: bortreb: ty

1:30 mudge: add-classpath is depreciated, what's the way to do it in clojure.1.1 ?

1:31 hiredman: don't

1:31 mudge: don't add to the classpath?

1:33 what if you can't set your classpath before hand and need to do it dynamically in your code?

1:35 tomoj: why would that be the case

2:02 bortreb: mudge: the classpath can't be changed after the jvm is initilized.

2:02 mudge: it's an annoying limitation of the jvm

2:03 mudge: http://stackoverflow.com/questions/252893/how-do-you-change-the-classpath-within-java

2:04 Bahman: bortreb: IIRC one can change classpath using the classloader.

2:04 System.class.getClassLoader.setClassPath()

2:05 Something "like" that.

2:05 hiredman: Bahman: no

2:05 Bahman: Or it was Runtime.getClassLoader()...can't remember well.

2:05 hiredman: no

2:06 Bahman: hiredman: I've done so in past.

2:06 bortreb: You can change the classpath IF you know what the main system classloader is but it's not gauranteed to always work across all jvms

2:06 hiredman: Bahman: no, you haven't

2:07 bortreb: as the stackoverflow answer sugests

2:07 hiredman: classloader has no such method

2:07 bortreb: you can get it with reflection but there's no "official" way to do it

2:07 hiredman: if you, you know, provide your own system classloader you can give it such a method

2:07 Bahman: hiredman: You are making me doubt it...but I've done so...just a moment I check if I still have the source code.

2:07 hiredman: Bahman: you've not

2:08 java provides no mechanisms for dynamicaly adding to the system classpath

2:09 tomoj: how do you provide your own system classloader?

2:09 hiredman: it's a -D

2:09 tomoj: aha

2:10 hiredman: http://gist.github.com/255766

2:10 tomoj: java.system.class.loader

2:11 hiredman: or http://gist.github.com/251980

2:11 if you don't like generating from asm

2:12 (no warranty on any of that, btw)

2:16 Blackfoot: anyone else having an issue loading clojure.contrib.json from 1.2.0-SNAPSHOT: ClassNotFoundException: clojure.contrib.pprint.PrettyWriter

2:22 tomoj: no

2:23 Blackfoot: huh maybe the jar is old clojure-contrib-1.2.0-20100615.150419-128.jar

2:23 tomoj: that's the same jar I have

2:24 and clojure.contrib.json does not mention PrettyWriter at all

2:26 Blackfoot: looks like it (:use [clojure.contrib.pprint :only (write formatter-out)]

2:26 tomoj: which causes no problems here

2:27 * hiredman uses clojure-json exclusively

2:28 Blackfoot: tomoj: well i guess that means i should be able to fix it :)

2:28 hiredman: ah good to know, though contrib is being used second hand in my case

2:48 tomoj: thanks, found the issue: old jar file in my java classpath

2:54 Bahman: hiredman: Couldn't find the source for the classpath stuff...but IIRC I used an approach similar to what bortreb pointed out to connect to a PG instance.

2:56 Is there any way to remove the first item of a vector?

2:58 mikem: Bahman: next

3:00 bortreb: Bahman: rest

3:01 Bahman: The difference is only the return value?

3:01 bortreb: no difference

3:02 , (= (class (next [1 2 3]))(class (rest [1 2 3])))

3:02 clojurebot: true

3:03 Bahman: bortreb: I mean in case there is no "rest" or "next".

3:03 bortreb: , (= (class (next []))(class (rest [])))

3:03 clojurebot: false

3:03 bortreb: interesting

3:03 Bahman: Alright...thanks.

3:04 next returns nil...rest returns [].

3:38 I'm writing a simple search function for a map with two arguments: key and value.

3:38 (defn product-find [key value)

3:38 (filter (fn [p] (= value (@p key))) @products))

3:39 It evaluates well in REPL but when I use it like (product-find [id 10001])

3:39 I get: Unable to resolve symbol: id in this context

3:40 mikem: Bahman: shouldn't id be a :id or "id" or something?

3:41 Bahman: mikem: (product-find [id 10001]) --> Unable to resolve symbol: id in this context

3:42 mikem: and what is 'id' ? is it bound to a value earlier somehow, in a let perhaps?

3:42 Bahman: id is a key in a structmap.

3:42 (defstruct product :id :name :code :note :weight :volume)

3:43 mikem: Bahman: then why are you calling (product-find) with 'id'? shouldn't you be calling with ':id' instead?

3:44 Bahman: mikem: If I use ':id' it throws Wrong number of args passed to: core$product-find

3:46 mikem: Bahman: hm, on a limb here, what if you pass (keyword "id") instead of :id?

3:48 Bahman: btw, looks like you don't have properly balanced brackets/parens in your definition of product-find, at least from the paste on IRC

3:49 Bahman: mikem: Let me try keyword version.

3:53 mikem: Bahman: this works for me: http://paste.lisp.org/display/112133

3:54 Bahman: Thank you mikem...I have to figure out why mine doesn't work.

3:54 mikem: look at your definition of product-find, the brackets/parentheses in your paste above were wrong

3:55 Bahman: Doh! Found the problem!

3:56 (product-find [id 10001]) I was passing the args as a vector :-)

3:56 mikem: Bahman: :)

3:56 Bahman: mikem: Thanks.

4:06 LauJensen: Morning all

4:07 Bahman: Morning LauJensen!

4:27 mudge: <bortreb>: maybe you can't change the classpath after the jvm initializes, but can you still load in new classes?

4:27 into java

4:34 hiredman: it's not that you cannot change the classpath, it's you cannot change the classpath of the system classloader

4:35 Bahman: hiredman: I agree :-)

4:36 mudge: i see

4:36 so you could make your own classloader with its own classpath?

5:14 bortreb: ok

5:14 here's how you can dynamically add stuff to the classpath

5:14 this works for me at least

5:15 (defn add-to-classpath [file-name] (wall-hack-method java.net.URLClassLoad\

5:15 er 'addURL [java.net.URL] (ClassLoader/getSystemClassLoader) (.toURL (file-str \

5:15 file-name))))

5:17 I made a random clojure project after initializing a jvm then called this with the path to the src directory of that project and was successfully able to load clojure files from that path. Beyond that I don't know if it will work for you.

5:33 mudge: bortreb, thank you, i'll try it out

5:34 bortreb: you'll need java-utils and duck-streams btw

5:43 mudge: does clojure make its own class loaders for its compiled code?

5:45 bortreb: mudge: I don't believe so - it seems to use the System ClassLoader

5:46 did add-to-classpath do anything for you?

5:48 mudge: bortreb: i haven't tried it yet, do don't have the code with me right now

5:50 bortreb: supposedly different "vendors" are free to implement even their own System Class-loader, which means that the hardcoded "addURL" method might not work universally

5:50 mudge: I just read that java webstart does not use the system loader, but uses a user-level classloader

5:51 so i guess i need to load my clojure code with the user classloader or change clojure to use the user classloader

5:52 LauJensen: Can the google groups be browsed via nntp ?

6:04 mudge: how does clojure know which classloader to use?

6:09 Bahman: LauJensen: I've searched for that a while ago and it seems it's not possible...GoogleGroups is just web UI.

6:17 mudge: does clojure use the system classloader by default? is there way to change the classloader that it uses?

6:21 anybody ever used *use-context-classloader* ?

8:13 Raynes: chouser: ping

8:13 mudge: pong

8:13 i love ping pong

8:13 Raynes: ;o

8:34 mikem: is there a function which appends one vector to another? ie [1 2] [3 4] -> [1 2 3 4]

8:34 LauJensen: ,(into [1 2 3] [4 5 6])

8:34 clojurebot: [1 2 3 4 5 6]

8:35 mikem: LauJensen: thanks. how does (concat) compare to this? (I just found concat)

8:35 the-kenny: ,(concat [1 2 3] [4 5 6])

8:35 clojurebot: (1 2 3 4 5 6)

8:35 the-kenny: concat returns a seq, not a vector

8:36 ,(doc concat)

8:36 clojurebot: "([] [x] [x y] [x y & zs]); Returns a lazy seq representing the concatenation of the elements in the supplied colls."

8:36 LauJensen: mikem: concat returns a lazyseq, into calls conj on each item, more effecient

8:36 sometimes concat might be what you want

8:36 ,(reduce conj [1 2 3] [4 5 6])

8:36 clojurebot: [1 2 3 4 5 6]

8:36 mikem: the-kenny: right, thanks :)

8:36 ok, got it

10:58 raek: should the body of a lazy-seq always return an ISeq object, or will any seqable object do?

11:08 LauJensen: raek: All sequable items implement ISeq

11:48 raek: ,(instance? clojure.lang.ISeq [1 2 3])

11:48 clojurebot: false

11:48 raek: ,(instance? clojure.lang.ISeq (seq [1 2 3]))

11:48 clojurebot: true

11:49 rhickey: ,(doc lazy-seq)

11:49 clojurebot: "([& body]); Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the body only the first time seq is called, and will cache the result and return it on all subsequent seq calls."

11:50 raek: so if I want a lazy-seq to return [1 2 3], I should wrap it in a seq call?

11:52 LauJensen: raek: I think so, yea

11:52 rhickey: raek: no lazy-seq will call seq, specifically so you can return [1 2 3] etc

11:52 apparently not documented

11:53 raek: can I assume that this will always work?

11:53 rhickey: raek: yes

11:54 ,(lazy-seq "fred")

11:54 clojurebot: (\f \r \e \d)

11:54 rhickey: (lazy-seq [1 2 3])

11:54 ,(lazy-seq [1 2 3])

11:54 clojurebot: (1 2 3)

12:10 Blackfoot: is there a way to System/setProperty in the resources path of a lein project?

12:16 arohner: Blackfoot: I believe you can put them in the :jvm-opts

12:16 Blackfoot: you might need lein 1.2 though

12:17 Blackfoot: luckily i upgraded just yesterday, i will check it out thanks

13:19 mudge: how long does it usually take for something to be approved that you posted to the clojure google group?

13:26 Nikelandjelo: Is there any macro, which takes map, keys. And creates local bindings for according keys? I only know how to do it with function arguments like this: (fn [ {:keys [a b c]} ] )

13:45 Blackfoot: arohner: :jvm-opts worked great, thanks

13:55 mudge: does anybody know how to tell clojure to use a custom classloader instead of the system classloader?

14:46 mrSpec/noobek can you make up your mind?

14:48 mrSpec: I've already made ;)

14:49 mudge: ^

14:49 mudge: okay mrSpec

15:28 Blackfoot: can protocols specify constructors

15:30 qbg: Blackfoot: What exactly do you want?

15:31 Blackfoot: qbg: i'd like to enforce classes implementing a protocol have a certain constructor signature

15:32 qbg: No.

15:32 At least not directly

15:32 Blackfoot: i guess the alternative is to have a method called "construct" or something that returns an instance

15:32 qbg: You could have a method in the protocol return a new object

15:33 But the issue there is what would you dispatch on?

15:35 Blackfoot: ah i see that problem

15:36 qbg: Why the need for a certain constructor signature?

15:36 Blackfoot: well the over all plan is to have a plugin type system

15:37 where the use select the type of "music player" they want to use

15:37 s/user selects/

15:38 so if all the music player plugins took the same constructor, it would make the plugin system more consistent

15:39 qbg: If the plugins are going to be written in Clojure, why not just specify a construct function that must exist in the plugin's namespace?

15:39 Blackfoot: yea, that should work

15:41 i'll try that out thanks

15:42 between defrecord and deftype, one would choose defrecord if the object that they're creating should implement IPersistentMap. otherwise just use deftype?

15:42 qbg: defrecord gives you a lot for free

15:43 I'd use defrecord unless you need you need to implement an interface differently than what defrecord gives you

15:44 Blackfoot: ok

15:45 qbg: deftype seems more suited for Clojure-in-Clojure usage

17:59 nardoni: What's the best way to require all files in a directory?

18:01 Blackfoot: nardoni: similar to java, i don't think there is an easy way

18:04 nardoni: Blackfoot:

18:04 woops

18:04 Blackfoot: you might be able to iterate over files with find-namespaces

18:04 http://richhickey.github.com/clojure-contrib/find-namespaces-api.html

18:05 nardoni: i'll check it out :)

18:05 Blackfoot: something like this http://learnclojure.blogspot.com/2010/02/requiring-all-possible-namespaces.html

18:07 nardoni: I'm trying to create a templating library, with templates being in plain clojure

18:08 I can get half way there with (load-string (slurp file)) and namespace pollution; but it's hardly ideal

18:08 (bare in mind, I'm new to clojure )

18:33 redalastor: I noticed nothing was pushed to the clojure repo for more than a week. Does it means we are close to a new release?

18:46 Blackfoot: how do i refer to a protocol defined in another namespace?

18:46 Chousuke: just like everything else.

18:46 the.namespace/Protocol

18:46 Blackfoot: (defrecord Foo [] other.namespace/Myprototype ...) throws a No such var:

18:47 Chousuke: at least, it worked for me last time I tried :P

18:47 Blackfoot: do i need to capture the result of defprotocol?

18:48 Chousuke: no

18:50 Blackfoot: hrm, maybe there is a circular dependency. play.clj both defines the protocol and :uses the defrecords based on the protocol

22:22 cais2002: what's typical strategy to resolve this: Reflection warning, twitter.clj:363 - call to java.io.File ctor can't be resolved.

22:23 danlarkin: phew! 363 lines!

22:23 split that bad boy up

22:24 you're calling the java.io.File constructor with args it doesn't take

22:29 cais2002: let me see, not my code

22:38 ok, it seems that two of File's constructor take 1 parameter, and clojure is not able to auto-derive which one to resolve to. adding type hint seems to address it

23:29 itistoday: why not= and not != ?

23:43 Bahman: Hi all!

Logging service provided by n01se.net