myk <mike.j.in...@gmail.com> writes: Hi!
> Hi - I'm pretty sure I've found a bug in the way eval (Clojure 1.4) > deals with fns that have closures (in that it doesn't). > > I've posted my examples on stack overflow, so I won't reproduce them here: > http://stackoverflow.com/questions/11191992/functions-with-closures-and-eval-in-clojure/11202589#11202589 > > I'm not sure of the usual procedure for things like this so I figured > I'd just let you guys know and see what you think. As the guys on stackoverflow already said, if think you need to use `eval` it is highly likely you are doing it wrong. That said, the last answer on stackoverflow seems to be correct. For example, when compiling classes for this code (ns testi.core) (let [noclo (fn [] "foo") s "foo" clo (fn [] s)] [(noclo) (clo)]) and disassembling them, you get: public final class testi.core$fn__2145$noclo__2146 extends clojure.lang.AFunction { public static {}; public testi.core$fn__2145$noclo__2146(); public java.lang.Object invoke(); } and public final class testi.core$fn__2145$clo__2148 extends clojure.lang.AFunction { java.lang.Object s; public static {}; public testi.core$fn__2145$clo__2148(java.lang.Object); public java.lang.Object invoke(); } So the function closing over s above has one additional constructor parameter, where the closed over value of s comes in to be set to the s field of the object. Bye, Tassilo -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en