[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using Macros in Lisp

 Bill St. Clair <bill@cambridge.apple.COM> writes:
 > I liked Drew McDermott's (and somebody else whose name I've forgotten
 > at the moment) "Artificial Intelligence Programming".
   [The authors of AI Programming are Charniak, Riesbeck & McDermott]

I think a contributing factor to the misunderstanding of macros is the
way they are described in many lisp texts (including "AI Programming",
2nd edition).  For example, "Macros are a special type of Lisp function.
They differ from the others in that they go through not one but two
rounds of evaluation."

This starts people off with the misconception that macros are functions.
They are not functions, they are a source code transformation mechanism.
(CLtL is careful to avoid this mistake, but I don't recommend referring
a novice lisp programmer to that text to learn lisp.) Failure to grasp
this transformational nature of macros leads to the well known macro
errors: accidently shadowing local variables, macro functions with side
effects, etc.

Another problem with the presentation of macros is that they are usually
introduced before backquote.  This hides the notion of macros as a
source to source transformation beneath many layers of list, cons and

"AI Programming" does have lots of examples, though.