#clojure logs

2008-06-02

12:06ericthorsenCan meta data go below a function definition? I thought you could say (defn f ([a1 a2]) #^{:meta-key "stuff"})
12:09ericthorsennevermind...I no longer need the #^
12:09ericthorsenthat's great!
14:50ericthorsenany reason I should not expect a clojure try block not to catch:
14:50ericthorsen(catch java.lang.IllegalThreadStateException exception
14:50ericthorsenif it is thrown?
14:51ericthorseni think I have a double negative there....a java.lang.IllegalThreadStateException exception is being thrown but does not appear to be getting caught in my clojure try block.
14:51rhickeyis it being thrown in the same thread?
15:12ericthorsenyes
15:13ericthorsen...well
15:13ericthorsenI'm calling Process.exitValue which throws this exception if the process is still running
15:14ericthorsenbut I calling that from the same thread that started the process
15:17rhickeyeric: It should be caught like any other Exception derivee
15:19ericthorsenok
15:19ericthorsenI put a (catch Throwable ...) and it caught that. Let me see if I can get a simple case to reproduce
15:19ericthorsenthanks
15:20rhickeyand was it really an IllegalThreadStateException?
16:24ericthorsenyes
16:34rhickeyhttp://clojure.org/news/primitive_support.html
16:41Chouse1very cool.
16:43Chouse1The final example on that page is very important.
16:44rhickeyyeah, I don't want people to go crazy over perf
16:45Chouse1sure, and as justification of the whole solution, as an answer to, "What's wrong with writing little bits of inner-loop code in Java (whether inlined or not)?"
16:46rhickeygiven macros, you'll be able to write much clearer code in Clojure than Java
16:47Chouse1compiler inlining is interesting -- do you generate that for all clojure functions?
16:48rhickeyNo, you have to specify the expansion, and it is only worth it for calls to Java that involve primitives
16:49Chouse1so is there new clojure syntax for that?
16:49rhickeyPlus, once inlined they are bound into the calling fn, no fixes, no dynamic rebinding
16:49Chouse1huh! I guess that makes sense.
16:49rhickeyThe compiler uses the :inline and :inline-arities metadata
16:49rhickeyplus there's a definline macro
16:50rhickeyshould only be used for one-liners
16:50rhickeyyou can see it in action in boot.clj, math stuff
16:50Chouse1so that gets inlined when a calling function is defined? that's roughly the same time as a called macro would be expanded, right?
16:51rhickeyright, like a macroexpansion
16:51rhickeycompletely at the option of the compiler, the code should be correct if the compiler chooses not to inline
16:53Chouse1the way lisp mixes compile/eval steps with each other still occasionally blows my mind.
16:56Chouse1seq is much faster for Java arrays, but fast enough to leave out areduce?
16:56Chouse1er, "not fast enough..?"
16:57rhickey(def fa (float-array (range 1000000)))
16:57rhickeyuser=> (time (reduce + fa))
16:57rhickey"Elapsed time: 41.666 msecs"
16:57rhickey4.9994036E11
16:57rhickeyuser=> (time (asum fa))
16:57rhickey"Elapsed time: 1.446 msecs"
16:57rhickey4.9994036E11
16:58rhickeyfast and faster
16:58rhickeyyou choose
16:58rhickeyif you wre doing serious graphics/audio stuff, you'd go with the latter
16:59rhickeyotherwise, use whatever is clearest
17:02rhickeythe vectors are no slouches either:
17:02rhickey(def va (map float (range 1000000)))
17:04rhickeyuser=> (time (reduce + va))
17:04rhickey"Elapsed time: 128.676 msecs"
17:04rhickey4.9994036E11
17:05rhickeyThat's a persistent collection and all boxed numbers
17:05Chouse1is primmath.clj not loaded by default like xml.clj and the others are?
17:05rhickeyprimmath is history
17:05Chouse1oh. no wonder it doesn't work. ;-)
17:05rhickeywill be gone soon
17:05Chouse1where's asum?
17:08rhickeyI haven't decided on what pre-defined array fns I'll supply, given I've just given everyone the tools to make their own
17:09rhickeyprimmath.clj is now gone
17:09Chouse1ok, I was just trying to reproduce your timing results.
17:09rhickeythe amap code is in the news item
17:09Chouse1ah. :-)
17:10rhickeyasum
17:10rhickeyamap and areduce are in boot.clj, asum and amul are in the news item
17:14Chouse1Would this approximate the behavior prior to your recent changes? (reduce + (into-array (range 1000000)))
17:15rhickeyyou should make the array outside of the time call to be fair
17:15Chouse1oh, of course.
17:16rhickeyalso note that if you are using integers, only the generic math will work
17:16rhickeyfor that number
17:17rhickeyalso into-array will make an array of boxed, you could have done (make-array (. Integer TYPE) 1000000)
17:18rhickeybut the dominant difference there will be primitive array seq, which used reflection. The new code is very much faster, before you get into the math ops
17:19rhickeymanipulation of arrays of primitives is hundreds of times faster than it was
18:57nsinghal(defn delete-directory [^File path]
18:57nsinghal (when (.exists path)
18:57nsinghal (let [files (.listFiles path)]
18:57nsinghal (doseq file files
18:57nsinghal (if (.isDirectory file)
18:57nsinghal (delete-directory file)
18:57nsinghal (.delete file))))))
18:58nsinghaljava.lang.Exception: Unsupported binding form: clojure.lang.PersistentList@e506a62e
18:58nsinghalclojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:2009: Unsupported binding form: clojure.lang.PersistentList@e506a62e
18:58nsinghalWhats wrong with this function?
19:23jamii_nsinghal: [#^FIle path]
19:58Lau_of_DKnsinghal, did you get it working?
23:09Chousernsinghal: leave out "^File" ... you don't need it.
23:10ChouserFor something that hits the disk like that, there's really no point.
23:10ChouserBut for a type hint, use #^File