#clojure log - Apr 29 2008

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

11:34 Chouser: rhickey: if I do (defn foo [] (+ 1 2)), that gets immediately compiled to bytecode, right? Is the (list '+ 1 2 3) symbol tree stored anywhere at all, or is it gone?

11:34 or more likely (list 'clojure/+ 1 2)

11:34 rhickey: it's gone

11:34 Chouser: ok, thanks.

14:08 wabash: rhickey: Does Clojure use the JVM GC?

14:08 rhickey: yes, completely Java's memory model

14:13 wabash: I may not understand Lisps completely, but isn't GC with Lisps a bit more complicated than in Java? I am thinking: reference counting on objects is easy, but then keeping track of closures, and which variables were present during closure creation => more complex? Or is it basically the same level of difficulty keeping track of object references and closure references?

14:13 rhickey: same stuff

14:14 Clojure fns are objects

14:35 mbeau: rhickey: nice work on closure; I haven't had much time to actually sit and play with it, but I really enjoyed your screencasts -- I ripped the audio from them and just listened while I commute

14:36 rhickey: thanks

14:36 wabash: rhickey: thanks for answering. I appreciate it.

14:37 mbeau: oops, slip of the finger: s/closure/Clojure/

15:24 abrooks: I used to mistype Clojure as Closure. Now I mistype closure as clojure. :)

15:53 rhickey: I have a map of agents called dist-matrix. I send one of the agents a function which will conditionally send the same function to other agents to recurse in a concurrent manner. I wanted to wait until they were all done so I naively said "(apply wait (vals dist-matrix))".

15:54 rhickey: can't call await in an action

15:54 abrooks: I wasn't awaiting in an action.

15:55 I did that in the main thread.

15:55 (send (dist-matrix start) #(wander start % 0))

15:55 (apply await (vals dist-matrix))

15:55 rhickey: and?

15:55 abrooks: wander will send itself conditionally to other agents in the dist-matrix.

15:56 rhickey: ok

15:56 you're wondering why await returned right away?

15:57 abrooks: Oh, await waits for a bit but the agents aren't done.

15:58 Hm. I'll check back in the logs in tomorrow... gotta bundle the kids into the car.

15:58 rhickey: the only thing you know will happen in await is it will only return after the actions you sent, but not the actions they sent etc

15:58 abrooks: Right. I realized that's what was happening.

15:59 Any way to achieve what I'm trying to?

15:59 Thanks. I'll check back for the answer later.

15:59 rhickey: If you know the number of kobs you can use CountDownLatch

15:59 jobs

18:13 leafw: hi all

18:13 question 1: how can I set the default stdout and stderr?

18:14 I may have overlooked it completely, but I can't find it

18:16 Chouser: http://clojure.org/reference/other_functions.html

18:17 Toward the bottom, look at the pr* functions and with-out-str

18:17 essentially, you want to use thread-local binding to point *out* at your own stdout stream.

18:18 I don't know if there's an equivalent for stderr or not.

18:19 leafw: hum

18:19 thank you

18:19 at least I see a way now

18:19 Chouser: there may be a java way underneath that, but I don't know anything about Java. :-)

18:19 leafw: question 2: how can I make a seq out of a native array made with make-array ? For example, I'd like to call (max some_array)

18:20 which fails, because it expects a sequence

18:20 (why aren't arrays sequences when needed?)

18:21 Chouser: (apply max some_array)

18:22 max takes multiple args, not a seq.

18:22 leafw: oh I see

18:22 let's try

18:22 Chouser: you can convert java array to seqs using (seq some_array)

18:23 sorry, not "convert", but more like "view"

18:23 you can view a java array as a seq using (seq some_array)

18:23 leafw: yes, 'view' is the right metaphor I'd like as well

18:23 hum

18:23 that always complains that java.lang.IllegalAccessError: Don't know how to create ISeq from arg

18:23 Chouser: and most builtin functions that operate on seqs use (seq) internally.

18:24 (apply max (into-array [1 2 3])) --> 3

18:24 There apply is doing seq on my array for me, so I don't have to explicitly.

18:25 leafw: the problem for me may be casting

18:25 I get an Object from a java class, which needs to be casted to a byte[]

18:25 or short[] or int[] ..

18:25 and seq on that object fails. But count works.

18:26 I am confused.

18:26 Chouser: any handy way for me to get such an Object?

18:29 (seq (make-array (Byte.TYPE) 3)) --> (0 0 0)

18:31 leafw: it's from ImageJ: (import '(ij ImagePlus) '(ij.process ByteProcessor) (let [bp (new ByteProcessor 512 512)] (apply max (seq (. bp (getPixels)))))

18:32 http://rsb.info.nih.gov/ij/upgrade/ij.jar

18:32 ( 1 Mb jar)

18:33 the problem may be the clojure version

18:33 your code fails

18:34 I have the default, not an svn snapshot

18:34 Chouser: ah. ok, that may indeed be the problem.

18:34 leafw: ok let me fetch the latest

18:34 Chouser: building using the svn version using ant is very straighforward.

18:34 ij

18:35 wrong window, sorry

18:43 maybe it was the . syntax that's failing for you. You could try (seq (make-array (. Byte TYPE) 3)) in your old Clojure

18:51 Your ByteProcessor example above returns 0 for me.

19:04 leafw: ok now it works

19:04 thanks Chouser

19:05 latest svn version solved the issue. So the release in the webpage is a bit behind ... the new notation (.someMEthod instnace) was not working either

19:11 * rhickey is trying to finish class generation before next release

19:11 rhickey: web site documents release

19:34 Chouser: leafw: np. glad you got it working.

19:35 rhickey: seq support for non-reference arrays is pretty new

Logging service provided by n01se.net