On Fri, Apr 9, 2010 at 10:04 AM, Douglas Philips <d...@mac.com> wrote:
> I'm trying to understand how the two forms here differ:
>
> In a fresh repl:
>
>        user=> '((a) (b) (c))
>        ((a) (b) (c))
>
> which is OK, those are just symbols.
>
> But then:
>
>        user=> (defn x [] (a) (b) (c))
>        java.lang.Exception: Unable to resolve symbol: a in this context
> (NO_SOURCE_FILE:2)
>
> so defn is doing something more than quoting the symbols (which quote did
> without generating an exception), but less than eval/execution.

It's not a defn thing. If you write (do (a) (b) (c)) at the REPL, you
should see the same exception.

When the compiler sees a symbol in expression context, it first checks
whether it is bound in the local environment:

    (let [x 42] x)

In this case, x is bound in the local environment.

If a symbol isn't bound in this way, the compiler will call (resolve
...) on the symbol at compile time. This yields some var v. The code
will then be evaluated as (deref v) at run time.

-Per

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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to