Common Lisp also has macros, which are much more
powerful than their
C counterparts. In Lisp, a macro is similar to a
function; however, instead of
computing a
value, a macro instead
computes a
form to be
evaluated in its place.
defmacro parses its argument list with
destructuring-bind, and thus makes it easy to define a macro with arbitrarily complex syntax. Macros usually make use of
backquote. An example (though not very useful) macro definition is:
(defmacro setq-3 (x y z)
`(progn (setq ,y ,z) (setq ,x ,y)))
macroexpand-1 and
macroexpand are useful for finding out exactly what a macro does.
CL macros, unfortunately, are not hygenic; that is, expanding an expression into a macro may cause free variables in the expression to be captured. Judicious use of gensym may help alleviate this problem, but there are cases where more is needed. Beginning with R5RS, Scheme supports hygenic macros, but Scheme isn't Common Lisp.