2008-06-02
| 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 | ericthorsen | nevermind...I no longer need the #^ |
| 12:09 | ericthorsen | that's great! |
| 14:50 | ericthorsen | any reason I should not expect a clojure try block not to catch: |
| 14:50 | ericthorsen | (catch java.lang.IllegalThreadStateException exception |
| 14:50 | ericthorsen | if it is thrown? |
| 14:51 | ericthorsen | 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 | ericthorsen | ...well |
| 15:13 | ericthorsen | I'm calling Process.exitValue which throws this exception if the process is still running |
| 15:14 | ericthorsen | 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 | ericthorsen | I put a (catch Throwable ...) and it caught that. Let me see if I can get a simple case to reproduce |
| 15:19 | ericthorsen | 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 | Chouse1 | 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 | rhickey | plus there's a definline macro |
| 16:50 | rhickey | should only be used for one-liners |
| 16:50 | rhickey | 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 | rhickey | 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 | Chouse1 | seq is much faster for Java arrays, but fast enough to leave out areduce? |
| 16:56 | Chouse1 | er, "not fast enough..?" |
| 16:57 | rhickey | (def fa (float-array (range 1000000))) |
| 16:57 | rhickey | user=> (time (reduce + fa)) |
| 16:57 | rhickey | "Elapsed time: 41.666 msecs" |
| 16:57 | rhickey | 4.9994036E11 |
| 16:57 | rhickey | user=> (time (asum fa)) |
| 16:57 | rhickey | "Elapsed time: 1.446 msecs" |
| 16:57 | rhickey | 4.9994036E11 |
| 16:58 | rhickey | fast and faster |
| 16:58 | rhickey | you choose |
| 16:58 | rhickey | if you wre doing serious graphics/audio stuff, you'd go with the latter |
| 16:59 | rhickey | otherwise, use whatever is clearest |
| 17:02 | rhickey | the vectors are no slouches either: |
| 17:02 | rhickey | (def va (map float (range 1000000))) |
| 17:04 | rhickey | user=> (time (reduce + va)) |
| 17:04 | rhickey | "Elapsed time: 128.676 msecs" |
| 17:04 | rhickey | 4.9994036E11 |
| 17:05 | rhickey | 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 | rhickey | 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 | rhickey | 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 | rhickey | for that number |
| 17:17 | rhickey | also into-array will make an array of boxed, you could have done (make-array (. Integer TYPE) 1000000) |
| 17:18 | rhickey | 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 | rhickey | manipulation of arrays of primitives is hundreds of times faster than it was |
| 18:57 | nsinghal | (defn delete-directory [^File path] |
| 18:57 | nsinghal | (when (.exists path) |
| 18:57 | nsinghal | (let [files (.listFiles path)] |
| 18:57 | nsinghal | (doseq file files |
| 18:57 | nsinghal | (if (.isDirectory file) |
| 18:57 | nsinghal | (delete-directory file) |
| 18:57 | nsinghal | (.delete file)))))) |
| 18:58 | nsinghal | java.lang.Exception: Unsupported binding form: clojure.lang.PersistentList@e506a62e |
| 18:58 | nsinghal | clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:2009: Unsupported binding form: clojure.lang.PersistentList@e506a62e |
| 18:58 | nsinghal | 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 | Chouser | For something that hits the disk like that, there's really no point. |
| 23:10 | Chouser | But for a type hint, use #^File |