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

Re: Parodies make everyone mad



At 12:28 PM -0500 11/18/02, Guy Steele - Sun Microsystems Labs wrote:
>
>If macros are part of
>the customary toolset of a community of programmers
>and there are guidelines and expectations about how they
>are and are not to be used, and about the level of
>documentation needed, then they need not be a problem.

This begs the question, what are a reasonable set of guidelines
for writing good macros in a language like Lisp or Scheme.  Here
are some rules of thumb I use; I'm embarrassed to write this
because the shortness of the list and the lack of rigor shows
the lack of depth in my thinking in this area.  I hope that
people who've thought more deeply and thoroughly will use this
as an excuse to write down a good list.

  - Don't include free references to "local" bindings.
    Unfortunately, I see this a lot from people who are
    not experienced macro writers.
  - Don't evaluate "value" parameters more than once.
    Do all evaluations "in order", unless there is a very
    good reason to do it otherwise.
  - Don't expand a "body" in more than one place, unless
    there's a very good reason to do otherwise.
  - If your language doesn't do "hygiene", do it by hand.
  - Macros aren't functions; don't use them where a function
    would do.  I hope your language and its compiler can do
    inlining without you having to resort to macros.
  - Stay close to the syntax of the "built-in" forms of the
    rest of your language.  Nobody likes having to learn
    lots of new syntax.