unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Pascal J. Bourguignon'" <pjb@informatimago.com>,
	<help-gnu-emacs@gnu.org>
Subject: RE: Is it possible for a macro to expand to nothing?
Date: Mon, 23 Nov 2009 14:09:13 -0800	[thread overview]
Message-ID: <F528683E35274FB9888103CD29F88EE0@us.oracle.com> (raw)
In-Reply-To: <87iqd1c7qn.fsf@galatea.local>

> > Huh? It produces the list ((setq bar 2)), assuming `ifdef' 
> > acts like `and'
> 
> Yes.  And ((setq bar 2)) is not a valid form.

Of course it's valid - it's a list.

Perhaps you are trying to _evaluate_ it? What you should be evaluating is the
entire list that results from macroexpanding the defmacro body. That list is a
defun sexp in Alan's case, and there is no problem evaluating it.

> So it is not a good idea, not a good style...
> 
> >> This is not a good property.  It would be
> >> better to keep the contract of macros, that is they take code, and
> >> they produce code, that is, valid forms.
> >
> > No idea what you are talking about.
> 
> Yes, that's the problem.
> 
> > It's simple, really: The code resulting from macroexpansion 
> > is a list.
> 
> No.  CODE resulting from macroexpansion should be CODE.  Not 
> just a list. If you want to get random lists, then use functions,
> not macros.  

The CODE resulting from the macroexpansion here is a _list_ whose car is
`defun'. It is a perfectly valid defun expression that can be evaluated without
error. It is CODE.

But the fact that the body of a defmacro should macroexpand to something that
can be evaluated without error is just background info. It is true for all
macros. It has nothing to do with the specific question Alan raised.

[And BTW, a sexp whose evaluation raises an error is not necessarily "invalid".
Validation requires validation against something (e.g. a syntax definition or a
specification). Lisp _syntax_ can be said to be invalid if it raises a read-time
error. But just because evaluating a sexp raises an error doesn't mean the
syntax is invalid. The list (bar) is not "invalid" if evaluating it raises the
error that bar's function definition is void.]





  reply	other threads:[~2009-11-23 22:09 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-23 14:56 Is it possible for a macro to expand to nothing? Alan Mackenzie
2009-11-23 16:03 ` Drew Adams
     [not found] ` <mailman.11344.1258992201.2239.help-gnu-emacs@gnu.org>
2009-11-23 16:31   ` Alan Mackenzie
2009-11-23 17:29     ` Drew Adams
2009-11-23 18:33     ` Pascal J. Bourguignon
2009-11-23 18:51       ` Drew Adams
     [not found]       ` <mailman.11354.1259004470.2239.help-gnu-emacs@gnu.org>
2009-11-23 20:08         ` Pascal J. Bourguignon
2009-11-23 20:24           ` Alan Mackenzie
2009-11-23 22:09           ` Drew Adams
     [not found]           ` <mailman.11367.1259014174.2239.help-gnu-emacs@gnu.org>
2009-11-23 23:55             ` Pascal J. Bourguignon
2009-11-24  0:55               ` Alan Mackenzie
2009-11-24  9:42                 ` Pascal J. Bourguignon
2009-11-24 10:45                   ` Alan Mackenzie
2009-11-24 11:14                     ` Pascal J. Bourguignon
2009-11-24 16:39                       ` Alan Mackenzie
2009-11-24 19:17                         ` Pascal J. Bourguignon
2009-11-25 14:13                         ` Jeff Clough
     [not found]                         ` <mailman.11467.1259158369.2239.help-gnu-emacs@gnu.org>
2009-11-26  6:53                           ` Alan Mackenzie
2009-11-26 11:11                             ` Pascal J. Bourguignon
2009-11-26 11:52                               ` Lennart Borgman
     [not found]                               ` <mailman.11564.1259236392.2239.help-gnu-emacs@gnu.org>
2009-11-26 12:16                                 ` Pascal J. Bourguignon
2009-11-26 12:43                                   ` Lennart Borgman
2009-11-27  8:32                         ` Kevin Rodgers
     [not found]                         ` <mailman.11626.1259310779.2239.help-gnu-emacs@gnu.org>
2009-11-27 13:15                           ` Alan Mackenzie
2009-11-27 13:52                             ` Pascal J. Bourguignon
2009-11-27 16:57                               ` Alan Mackenzie
2009-11-27 17:09                                 ` Pascal J. Bourguignon
2009-11-27 17:19                               ` Helmut Eller
2009-11-27 17:45                                 ` Pascal J. Bourguignon
2009-11-27 23:17                             ` Tim X
2009-11-28  0:06                               ` Pascal J. Bourguignon
2009-11-28  8:29                                 ` Alan Mackenzie
2009-11-28 10:25                                   ` Pascal J. Bourguignon
2009-11-28 12:57                                     ` Thierry Volpiatto
     [not found]                                     ` <mailman.11699.1259413441.2239.help-gnu-emacs@gnu.org>
2009-11-29  0:54                                       ` Pascal J. Bourguignon
2009-11-24 11:56                     ` Pascal J. Bourguignon
     [not found]     ` <mailman.11352.1258997403.2239.help-gnu-emacs@gnu.org>
2009-11-23 18:42       ` Pascal J. Bourguignon
2009-11-23 20:12         ` Drew Adams
     [not found]         ` <mailman.11356.1259007263.2239.help-gnu-emacs@gnu.org>
2009-11-23 20:21           ` Pascal J. Bourguignon
2009-11-23 22:09             ` Drew Adams [this message]
     [not found]             ` <mailman.11368.1259014177.2239.help-gnu-emacs@gnu.org>
2009-11-24  0:03               ` Pascal J. Bourguignon
2009-11-23 20:09       ` Alan Mackenzie
2009-11-23 16:49 ` Jeff Clough

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F528683E35274FB9888103CD29F88EE0@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=pjb@informatimago.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).