Ah, I found out that java bytecode can't contain data literals so the compiler has to emit a constructor instead.
Also, since the jvm doesn't gc classes there might be confusing memory leaks if you could embed a closure in evaluated code. On 9 August 2013 09:13, Christophe Grand <christo...@cgrand.net> wrote: > You are right, it's beacsue of print-dup. Hence it works only on functions > which aren't closures: > > => (let [a nil x (fn [] a)] (eval [x])) > IllegalArgumentException No matching ctor found for class > user$eval3989$x__3990 > > > Why is emitValue used? > Regular code forms (as returned by the reader) don't usually contain > functions. When the compiler doesn't know how to evaluate some value it > treats it as a constant. Constants are serialized in the class and read > back/instanciated when the class is loaded. > > > On Thu, Aug 8, 2013 at 6:30 PM, Jamie Brandon <ja...@scattered-thoughts.net> > wrote: >> >> The Fn case works because print-dup is defined on fns: >> >> user=> (binding [*print-dup* true] (println (fn [] nil))) >> #=(user$eval2502$fn__2503. ) >> nil >> user=> (read-string "#=(user$eval2502$fn__2503. )") >> #<user$eval2502$fn__2503 user$eval2502$fn__2503@19037d90> >> >> I still can't figure out why Compiler.emitValue is used though. Am I >> right in thinking that clojure.core/eval is not calling the function >> that the compiler uses, but instead serializing everything and pushing >> it through the same pathway as compiling text files? >> >> On 8 August 2013 16:43, Christophe Grand <christo...@cgrand.net> wrote: >> > Right now I ca't figure why the fn case is working but the anonyous Var >> > is >> > failing because the vars are specially handled: >> > >> > else if(value instanceof Var) >> > { >> > Var var = (Var) value; >> > gen.push(var.ns.name.toString()); >> > gen.push(var.sym.toString()); >> > gen.invokeStatic(RT_TYPE, Method.getMethod("clojure.lang.Var >> > var(String,String)")); >> > } >> > >> > Christophe >> > >> > >> > >> > On Thu, Aug 8, 2013 at 4:44 PM, Jamie Brandon >> > <ja...@scattered-thoughts.net> >> > wrote: >> >> >> >> What if it isn't inside a constant? >> >> >> >> user=> (eval `(fn [] ~#'x)) >> >> #<user$eval1366$fn__1367 user$eval1366$fn__1367@15dbb76> >> >> >> >> user=> (with-local-vars [x nil] (eval `(fn [] ~x))) >> >> CompilerException java.lang.NullPointerException, >> >> compiling:(NO_SOURCE_PATH:1:1) >> >> >> >> How about functions? These are unreadable but they still eval >> >> correctly inside constants. >> >> >> >> user=> (letfn [(x [] nil)] (eval x)) >> >> #<user$eval1377$x__1378 user$eval1377$x__1378@5fea6729> >> >> >> >> user=> (letfn [(x [] nil)] (eval [x])) >> >> [#<user$eval1381$x__1382 user$eval1381$x__1382@e3b7c27>] >> >> >> >> user=> (read-string "#<user$x user$x@1981e4d>") >> >> RuntimeException Unreadable form clojure.lang.Util.runtimeException >> >> (Util.java:219) >> >> >> >> user=> (defn x [] nil) >> >> #'user/x >> >> >> >> user=> (eval x) >> >> #<user$x user$x@14ff1714> >> >> >> >> user=> (eval [x]) >> >> [#<user$x user$x@5892d4a8>] >> >> >> >> user=> (read-string "#<user$eval1381$x__1382 >> >> user$eval1381$x__1382@e3b7c27>") >> >> RuntimeException Unreadable form clojure.lang.Util.runtimeException >> >> (Util.java:219) >> >> >> >> On 8 August 2013 14:58, Christophe Grand <christo...@cgrand.net> wrote: >> >> > The error is caused by the fact that eval sees the var as a constant >> >> > (or >> >> > part of) and tries to serialize the constant. >> >> > #<Var: --unnamed--> is unreadable while #'user/x is that explains teh >> >> > difference in behaviour. >> >> > >> >> > >> >> > On Thu, Aug 8, 2013 at 3:40 PM, Jamie Brandon >> >> > <ja...@scattered-thoughts.net> >> >> > wrote: >> >> >> >> >> >> This has me stumped: >> >> >> >> >> >> user=> (with-local-vars [x nil] (eval x)) >> >> >> #<Var: --unnamed--> >> >> >> user=> (with-local-vars [x nil] (eval [x])) >> >> >> CompilerException java.lang.NullPointerException, >> >> >> compiling:(NO_SOURCE_PATH:1:1) >> >> >> >> >> >> By comparison: >> >> >> >> >> >> user=> (def x nil) >> >> >> #'user/x >> >> >> user=> (eval #'x) >> >> >> #'user/x >> >> >> user=> (eval [#'x]) >> >> >> [#'user/x] >> >> >> >> >> >> -- >> >> >> -- >> >> >> 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 >> >> >> --- >> >> >> You received this message because you are subscribed to the Google >> >> >> Groups >> >> >> "Clojure" group. >> >> >> To unsubscribe from this group and stop receiving emails from it, >> >> >> send >> >> >> an >> >> >> email to clojure+unsubscr...@googlegroups.com. >> >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> >> >> >> >> > >> >> > >> >> > >> >> > -- >> >> > On Clojure http://clj-me.cgrand.net/ >> >> > Clojure Programming http://clojurebook.com >> >> > Training, Consulting & Contracting http://lambdanext.eu/ >> >> > >> >> > -- >> >> > -- >> >> > 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 >> >> > --- >> >> > You received this message because you are subscribed to the Google >> >> > Groups >> >> > "Clojure" group. >> >> > To unsubscribe from this group and stop receiving emails from it, >> >> > send >> >> > an >> >> > email to clojure+unsubscr...@googlegroups.com. >> >> > For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> -- >> >> -- >> >> 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 >> >> --- >> >> You received this message because you are subscribed to the Google >> >> Groups >> >> "Clojure" group. >> >> To unsubscribe from this group and stop receiving emails from it, send >> >> an >> >> email to clojure+unsubscr...@googlegroups.com. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> > >> > >> > >> > >> > -- >> > On Clojure http://clj-me.cgrand.net/ >> > Clojure Programming http://clojurebook.com >> > Training, Consulting & Contracting http://lambdanext.eu/ >> > >> > -- >> > -- >> > 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 >> > --- >> > You received this message because you are subscribed to the Google >> > Groups >> > "Clojure" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> > an >> > email to clojure+unsubscr...@googlegroups.com. >> > For more options, visit https://groups.google.com/groups/opt_out. >> >> -- >> -- >> 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 >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > On Clojure http://clj-me.cgrand.net/ > Clojure Programming http://clojurebook.com > Training, Consulting & Contracting http://lambdanext.eu/ > > -- > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.