#clojure log - Jun 02 2008

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

12:06 ericthorsen: Can meta data go below a function definition? I thought you could say (defn f ([a1 a2]) #^{:meta-key "stuff"})

12:09 nevermind...I no longer need the #^

12:09 that's great!

14:50 any reason I should not expect a clojure try block not to catch:

14:50 (catch java.lang.IllegalThreadStateException exception

14:50 if it is thrown?

14:51 i 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:51 rhickey: is it being thrown in the same thread?

15:12 ericthorsen: yes

15:13 ...well

15:13 I'm calling Process.exitValue which throws this exception if the process is still running

15:14 but I calling that from the same thread that started the process

15:17 rhickey: eric: It should be caught like any other Exception derivee

15:19 ericthorsen: ok

15:19 I put a (catch Throwable ...) and it caught that. Let me see if I can get a simple case to reproduce

15:19 thanks

15:20 rhickey: and was it really an IllegalThreadStateException?

16:24 ericthorsen: yes

16:34 rhickey: http://clojure.org/news/primitive_support.html

16:41 Chouse1: very cool.

16:43 The final example on that page is very important.

16:44 rhickey: yeah, I don't want people to go crazy over perf

16:45 Chouse1: sure, 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:46 rhickey: given macros, you'll be able to write much clearer code in Clojure than Java

16:47 Chouse1: compiler inlining is interesting -- do you generate that for all clojure functions?

16:48 rhickey: No, you have to specify the expansion, and it is only worth it for calls to Java that involve primitives

16:49 Chouse1: so is there new clojure syntax for that?

16:49 rhickey: Plus, once inlined they are bound into the calling fn, no fixes, no dynamic rebinding

16:49 Chouse1: huh! I guess that makes sense.

16:49 rhickey: The compiler uses the :inline and :inline-arities metadata

16:49 plus there's a definline macro

16:50 should only be used for one-liners

16:50 you can see it in action in boot.clj, math stuff

16:50 Chouse1: so that gets inlined when a calling function is defined? that's roughly the same time as a called macro would be expanded, right?

16:51 rhickey: right, like a macroexpansion

16:51 completely at the option of the compiler, the code should be correct if the compiler chooses not to inline

16:53 Chouse1: the way lisp mixes compile/eval steps with each other still occasionally blows my mind.

16:56 seq is much faster for Java arrays, but fast enough to leave out areduce?

16:56 er, "not fast enough..?"

16:57 rhickey: (def fa (float-array (range 1000000)))

16:57 user=> (time (reduce + fa))

16:57 "Elapsed time: 41.666 msecs"

16:57 4.9994036E11

16:57 user=> (time (asum fa))

16:57 "Elapsed time: 1.446 msecs"

16:57 4.9994036E11

16:58 fast and faster

16:58 you choose

16:58 if you wre doing serious graphics/audio stuff, you'd go with the latter

16:59 otherwise, use whatever is clearest

17:02 the vectors are no slouches either:

17:02 (def va (map float (range 1000000)))

17:04 user=> (time (reduce + va))

17:04 "Elapsed time: 128.676 msecs"

17:04 4.9994036E11

17:05 That's a persistent collection and all boxed numbers

17:05 Chouse1: is primmath.clj not loaded by default like xml.clj and the others are?

17:05 rhickey: primmath is history

17:05 Chouse1: oh. no wonder it doesn't work. ;-)

17:05 rhickey: will be gone soon

17:05 Chouse1: where's asum?

17:08 rhickey: I 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:09 primmath.clj is now gone

17:09 Chouse1: ok, I was just trying to reproduce your timing results.

17:09 rhickey: the amap code is in the news item

17:09 Chouse1: ah. :-)

17:10 rhickey: asum

17:10 amap and areduce are in boot.clj, asum and amul are in the news item

17:14 Chouse1: Would this approximate the behavior prior to your recent changes? (reduce + (into-array (range 1000000)))

17:15 rhickey: you should make the array outside of the time call to be fair

17:15 Chouse1: oh, of course.

17:16 rhickey: also note that if you are using integers, only the generic math will work

17:16 for that number

17:17 also into-array will make an array of boxed, you could have done (make-array (. Integer TYPE) 1000000)

17:18 but 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:19 manipulation of arrays of primitives is hundreds of times faster than it was

17:19 * rhickey running

18:57 nsinghal: (defn delete-directory [^File path]

18:57 (when (.exists path)

18:57 (let [files (.listFiles path)]

18:57 (doseq file files

18:57 (if (.isDirectory file)

18:57 (delete-directory file)

18:57 (.delete file))))))

18:58 java.lang.Exception: Unsupported binding form: clojure.lang.PersistentList@e506a62e

18:58 clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:2009: Unsupported binding form: clojure.lang.PersistentList@e506a62e

18:58 Whats wrong with this function?

19:23 jamii_: nsinghal: [#^FIle path]

19:58 Lau_of_DK: nsinghal, did you get it working?

23:09 Chouser: nsinghal: leave out "^File" ... you don't need it.

23:10 For something that hits the disk like that, there's really no point.

23:10 But for a type hint, use #^File

Logging service provided by n01se.net