On 3 Sep 2009, at 08:24, Miron Brezuleanu wrote:

> 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 of http://clojure.org/evaluation, my
> code should simply return 2.

The critical point here is the environment in which eval evaluates its  
argument. This is not specified on the documentation page you cite.  
Eval uses the environment of the current namespace, not taking into  
account the lexical environment surrounding the call to eval itself.  
Said differently, the result is the same as if the argument to eval  
were placed at the outermost expression level of the module inside  
which eval is called.

Two examples that do work are

1)      (eval '(let [x 1] (inc x)))
Here the lexical scope is created inside the evaluated expression.

2)      (def y 2)
        (eval '(inc y))
Here the argument to inc is defined in the namespace before eval is  
called.

Konrad.

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