On Fri, Jan 6, 2012 at 11:12 AM, Andrew <ache...@gmail.com> wrote:
> http://en.wikibooks.org/wiki/Learning_Clojure/Macros
>
> The page says the following:
>
> (def pointless (fn [n] n))
>
> "Whatever is passed to this macro---a list, a symbol, whatever---will be
> returned unmolested and then evaluated after the call. Effectively, calling
> this macro is pointless:"
>
> (pointless (+ 3 5))   ; pointless returns the list (+ 3 5), which is then
> evaluated in its place
> (+ 3 5)               ; may as well just write this instead
>
>
> But actually, doesn't (+ 3 5) get evaluated before pointless ever sees it?

No. Macro arguments are passed as unevaluated forms. However, numbers
and data structures are still usable. If you pass 3 to a macro you can
add to it, check that it's odd, etc. in the macro; if you pass [7 8 (*
4 5)] the macro code sees, and can traverse, a vector with the
integers 7 and 8 in it -- but the last component of the vector will be
the list '(* 4 5) rather than the number 20.

The macro can always emit code that will process the evaluated items.
For example, it can emit `(reduce + ~v) with v having been that
vector, and the output of '(reduce + [7 8 (* 4 5)]) will evaluate to
35, as it should.

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