On Sat, Nov 27, 2010 at 10:45 AM, Eduardo Julian <eduardo...@gmail.com> wrote: > user=> (let [a 'b] (str a)) > "b" > user=> (let [b 5 a 'b] (eval a)) > java.lang.Exception: Unable to resolve symbol: b in this context > (repl-1:7) > user=> (let [a 'b b 5] (eval a)) > java.lang.Exception: Unable to resolve symbol: b in this context > (repl-1:9) > > user=> (def b 5) > #'user/b > user=> (def a 'b) > #'user/a > user=> a > b > userr=> (eval a) > 5 > > How come this problem happens inside the let but not with def?
If you (do (binding [*ns* (find-ns 'foo)] (eval bar))) the evaluation of bar sees the global bindings in the namespace foo, and can get at other global bindings and Java classes with fully-qualified names, but cannot see the lexical environment around the eval call. Even when called inside a let or a function body, eval's contents only see what they would see if executed at the top level of the source file for the namespace that is *current when eval is called* (not necessarily the same file the eval itself is in). -- 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