On Sep 3, 9:24 am, Miron Brezuleanu <mbr...@gmail.com> wrote:
> Hello,
>
> I'm a Clojure newbie (many thanks to Rich Hickey and everyone involved
> - it's a great programming environment) and I have some trouble with
> 'eval'.
>
> What I'm trying is:
> $ java -cp clojure.jar clojure.lang.Repl
> Clojure 1.1.0-alpha-SNAPSHOT
> user=> (let [x 1] (eval '(inc x)))
> java.lang.Exception: Unable to resolve symbol: x in this context
> (NO_SOURCE_FILE:1)
>
> (on a freshly downloaded&compiled clojure from github)
>
> According to my understanding ofhttp://clojure.org/evaluation, my
> code should simply return 2.
>
> What am I missing? :-)

Eval has no access to its lexical environment at runtime; you can only
use global bindings.

The syntax-quote trick Christian showed works because it expands to
something similar to (eval (list 'inc x)), and when eval is called,
the (list 'inc x) is evaluated (as function parameters are), the value
of x in the lexical context is available and the argument to eval
becomes '(inc 2), which works. (nb. eval can evaluate the inc symbol
because it names a global Var.)

I hope I managed to explain this clearly enough. I'm not sure I could
understand this explanation if I didn't already. :)

--
Jarkko
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to