Re: Confused by var eval behaviour

2013-08-09 Thread Jamie Brandon
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 wrote: > You are

Re: Confused by var eval behaviour

2013-08-09 Thread Christophe Grand
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 us

Re: Confused by var eval behaviour

2013-08-08 Thread Jamie Brandon
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. )") # I still can't figure out why Compiler.emitValue is used though. Am I right in thinking that cloju

Re: Confused by var eval behaviour

2013-08-08 Thread Christophe Grand
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());

Re: Confused by var eval behaviour

2013-08-08 Thread Jamie Brandon
This actually seems to work for deftypes too: user=> (deftype Foo []) user.Foo user=> (eval (Foo.)) # user=> (eval [(Foo.)]) [#] But not for arbitrary objects: user=> (eval (java.io.StringReader. "foo")) # user=> (eval [(java.io.StringReader. "foo")]) CompilerException java.lang.RuntimeExceptio

Re: Confused by var eval behaviour

2013-08-08 Thread Jamie Brandon
What if it isn't inside a constant? user=> (eval `(fn [] ~#'x)) # 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=

Re: Confused by var eval behaviour

2013-08-08 Thread Christophe Grand
The error is caused by the fact that eval sees the var as a constant (or part of) and tries to serialize the constant. # is unreadable while #'user/x is that explains teh difference in behaviour. On Thu, Aug 8, 2013 at 3:40 PM, Jamie Brandon wrote: > This has me stumped: > > user=> (with-local-v

Confused by var eval behaviour

2013-08-08 Thread Jamie Brandon
This has me stumped: user=> (with-local-vars [x nil] (eval x)) # 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] --