On 27 сен, 16:45, Mark Rathwell <mark.rathw...@gmail.com> wrote:
> > And in this case Closure compiler behave itself also unpredictably and
> > quite the contrary:
> > Where it must evaluate a symbol (like in this case), it doesn't.
>
> Symbols need to be namespace resolved in order to be evaluated
> properly.  This is something you need to be aware of, but it is not
> unpredictable or contrary to any documentation.  And again, in this
> case, the evaluation of the plus symbol does not happen at macro
> expansion, it happens at run time.  The behavior here is the same
> inside of and outside of a macro:
>
> user=> (def e '(5 + 2))
> #'user/e
> user=> (eval `((nth '~e 1) (nth e 0) (nth e 2)))
> 2
> user=> (eval `((nth (list ~@e) 1) (nth e 0) (nth e 2)))
> 7
>
> > Where it mustn't evaluate a symbol (argument of macro), it does.
>
> This has already been shown in several responses, the argument is not
> being evaluated in macro expansion, it is being evaluated at runtime.

In this point I want to cite Clojure doc, that say nothing about
expansion and runtime,  once more: "..If the operator of a call is a
symbol that names a global var that is a macro function, that macro
function is called and is passed the /unevaluated/ operand forms. "
So, when I write the macro function body, I expect that operands are
unevaluated when my body is executed to get an expanded form (finally
expanded), that will be executed afterward to get a result (at
runtime, as you say). But this is not the case in the very first
example:

user=> (defmacro infix [e] `(let [[x# f# y#] ~e] (f# x# y#)))
#'user/infix
user=> (infix (5 + 4))
java.lang.ClassCastException: java.lang.Integer cannot be cast to
clojure.lang.IFn (NO_SOURCE_FILE:0)

I insist that expansion is not quite correct. Am I right?

> Using macroexpand will help you to see what the expanded forms look
> like and what namespace symbols are resolved to.

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