I see. That section is just horribly written, calling something a macro 
when it isn't one yet. Here's my thinking in **bold**, inlined.

Simple Macro

If you understand the reader and evaluator, there actually isn't all that 
much more to understand about the operation and creation of macros, for a 
macro is simply a regular function that is called in a special way. When 
called as a macro, a function takes its arguments *un*evaluated and returns 
an expression to be evaluated in place of the call to the macro. A very 
simple (and pointless) macro would be one that simply returns its argument. 
**Here's a first attempt which is NOT a macro:**

(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. **At least, that's 
what we want to happen, and that's what would happen to a real macro. But 
this is not a real macro yet.** Effectively, calling this macro is 
pointless:* *And if this were a real macro, this is what would happen:**

(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 as we defined *pointless* above, it is just a regular function, not a 
macro. **The argument to pointless (+ 3 5) gets evaluated to 5 and then 
enters the body of the function, which simply returns 5.** To make it a 
macro, we need to attach the key-value pair :macro true as metadata to the 
Var mapped to *pointless* by the def. There are a number of ways to do 
this, but most commonly we would simply define the function as a macro with 
the provided macro *clojure/defmacro*:

(defmacro pointless [n] n)   ; define a macro pointless that takes one 
parameter and simply returns it **...without evaluating it -- now it behaves as 
we intended in the previous code snippet on this page**

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