help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Is it possible for a macro to expand to nothing?


From: Jeff Clough
Subject: Re: Is it possible for a macro to expand to nothing?
Date: Wed, 25 Nov 2009 09:13:16 -0500 (EST)

From: Alan Mackenzie <acm@muc.de>
Date: Tue, 24 Nov 2009 16:39:20 +0000 (UTC)

>> It comes directly from the definition of defmacro,
> 
>>    defmacro is a special form in `src/eval.c'.
>>    (defmacro name arglist [docstring] [decl] body...)
> 
>>    Define name as a macro.
>>    The actual definition looks like
>>     (macro lambda arglist [docstring] [decl] body...).
>>    When the macro is called, as in (name ARGS...),
>>    the function (lambda arglist body...) is applied to
>>    the list ARGS... as it appears in the expression,
>>    and the result should be a form to be evaluated instead of the original.
> 
> Oh, come on!  That last sentence is a tutorial, motivating one, expressed
> in the slightly loose, colloquial language of the hacker.  "a form to be
> evaluated" is here shorthand for something like "some sort of atom or
> list structure which fits into the slot where the invocation is housed"

This is incorrect.  The term "form" has a very specific definition in
Lisp.  It is a sexp that can be evaluated.  While I'm new to Lisp, I
have been knee deep in books and documents for the last couple of
weeks and everything (including the GNU Emacs Lisp Manual) presents
macros as a way to generate *forms*, not just sexps.

If you have a macro that expands to (1 2 3), it's not going to break
the world, but that macro isn't doing what every hacker is going to
expect.  I'd call that a style problem.

If, for some reason, you absolutely have to use a macro to generate
something like that above, at least have it expand to (list 1 2 3),
that way the macro can still be evaluated and no one gets shafted.
You get the behavior you want and the macro is still expanding to a
valid form.

Jeff





reply via email to

[Prev in Thread] Current Thread [Next in Thread]