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

Yes, it is the case.  The operands are not evaluated in the expansion
of the macro call, they are evaluated when that expanded code is
executed at run time.

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

No, you are incorrect.  The expansion happens as would be expected,
and is completely consistent with the documentation.  If you use
macroexpand here, it is clear what is going on.  The expansion of your
macro contains a call to a function '5', which is an integer, and
cannot be cast to a function.  As I stated previously, you want a list
here, not a function call.

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