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

Re: Using Macros in Lisp

Let's try not to go into style wars. I think each of you is right in some
points. You should avoid macros if you do not understand how they work, and
you should avoid macros that duplicate existing features (but I won't pretend
I am following these rules :-)
Now a question like "What are macros for?" is sure to generate a long dis-
cussion. I won't resist adding my few contributions:
- Macros are not made for inline expansion (a la C++). The performance gain
is not worth it.
- I use macros that expand into very simple expressions to "rename" things.
For instance I may define synonyms of first, second, ... to give a structure
to a list (this could be done with defstruct too).
- I use wrapper macros (traditionnaly named with-xx) that have a &body argument
and wrap it in a let and maybe an unwind-protect.
- I use "compiler macros", that in effect define a language and compile it
into a (hopefully) efficient Common Lisp form. This kind of macros generally
requires one or more auxillary functions, and a lot of coffee, but the result
is worth it (not to mention the personal satisfaction :-)
     Daniel Ranson