#clojure logs

2008-05-01

11:34Chouserrhickey: 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:34Chouseror more likely (list 'clojure/+ 1 2)
11:34rhickeyit's gone
11:34Chouserok, thanks.
14:08wabashrhickey: Does Clojure use the JVM GC?
14:08rhickeyyes, completely Java's memory model
14:13wabashI 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:13rhickeysame stuff
14:14rhickeyClojure fns are objects
14:35mbeaurhickey: 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:36rhickeythanks
14:36wabashrhickey: thanks for answering. I appreciate it.
14:37mbeauoops, slip of the finger: s/closure/Clojure/
15:24abrooksI used to mistype Clojure as Closure. Now I mistype closure as clojure. :)
15:53abrooksrhickey: 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:54rhickeycan't call await in an action
15:54abrooksI wasn't awaiting in an action.
15:55abrooksI did that in the main thread.
15:55abrooks(send (dist-matrix start) #(wander start % 0))
15:55abrooks(apply await (vals dist-matrix))
15:55rhickeyand?
15:55abrookswander will send itself conditionally to other agents in the dist-matrix.
15:56rhickeyok
15:56rhickeyyou're wondering why await returned right away?
15:57abrooksOh, await waits for a bit but the agents aren't done.
15:58abrooksHm. I'll check back in the logs in tomorrow... gotta bundle the kids into the car.
15:58rhickeythe 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:58abrooksRight. I realized that's what was happening.
15:59abrooksAny way to achieve what I'm trying to?
15:59abrooksThanks. I'll check back for the answer later.
15:59rhickeyIf you know the number of kobs you can use CountDownLatch
15:59rhickeyjobs
18:13leafwhi all
18:13leafwquestion 1: how can I set the default stdout and stderr?
18:14leafwI may have overlooked it completely, but I can't find it
18:16Chouserhttp://clojure.org/reference/other_functions.html
18:17ChouserToward the bottom, look at the pr* functions and with-out-str
18:17Chouseressentially, you want to use thread-local binding to point *out* at your own stdout stream.
18:18ChouserI don't know if there's an equivalent for stderr or not.
18:19leafwhum
18:19leafwthank you
18:19leafwat least I see a way now
18:19Chouserthere may be a java way underneath that, but I don't know anything about Java. :-)
18:19leafwquestion 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:20leafwwhich fails, because it expects a sequence
18:20leafw(why aren't arrays sequences when needed?)
18:21Chouser(apply max some_array)
18:22Chousermax takes multiple args, not a seq.
18:22leafwoh I see
18:22leafwlet's try
18:22Chouseryou can convert java array to seqs using (seq some_array)
18:23Chousersorry, not "convert", but more like "view"
18:23Chouseryou can view a java array as a seq using (seq some_array)
18:23leafwyes, 'view' is the right metaphor I'd like as well
18:23leafwhum
18:23leafwthat always complains that java.lang.IllegalAccessError: Don't know how to create ISeq from arg
18:23Chouserand most builtin functions that operate on seqs use (seq) internally.
18:24Chouser(apply max (into-array [1 2 3])) --> 3
18:24ChouserThere apply is doing seq on my array for me, so I don't have to explicitly.
18:25leafwthe problem for me may be casting
18:25leafwI get an Object from a java class, which needs to be casted to a byte[]
18:25leafwor short[] or int[] ..
18:25leafwand seq on that object fails. But count works.
18:26leafwI am confused.
18:26Chouserany handy way for me to get such an Object?
18:29Chouser(seq (make-array (Byte.TYPE) 3)) --> (0 0 0)
18:31leafwit's from ImageJ: (import '(ij ImagePlus) '(ij.process ByteProcessor) (let [bp (new ByteProcessor 512 512)] (apply max (seq (. bp (getPixels)))))
18:32leafwhttp://rsb.info.nih.gov/ij/upgrade/ij.jar
18:32leafw( 1 Mb jar)
18:33leafwthe problem may be the clojure version
18:33leafwyour code fails
18:34leafwI have the default, not an svn snapshot
18:34Chouserah. ok, that may indeed be the problem.
18:34leafwok let me fetch the latest
18:34Chouserbuilding using the svn version using ant is very straighforward.
18:34Chouserij
18:35Chouserwrong window, sorry
18:43Chousermaybe it was the . syntax that's failing for you. You could try (seq (make-array (. Byte TYPE) 3)) in your old Clojure
18:51ChouserYour ByteProcessor example above returns 0 for me.
19:04leafwok now it works
19:04leafwthanks Chouser
19:05leafwlatest 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:11rhickeyweb site documents release
19:34Chouserleafw: np. glad you got it working.
19:35rhickeyseq support for non-reference arrays is pretty new