all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Is it possible for a macro to expand to nothing?
Date: Tue, 24 Nov 2009 10:45:32 +0000 (UTC)	[thread overview]
Message-ID: <hegdgc$18ah$1@colin2.muc.de> (raw)
In-Reply-To: 87pr78b6n9.fsf@galatea.local

Pascal J. Bourguignon <pjb@informatimago.com> wrote:
> Alan Mackenzie <acm@muc.de> writes:

>> Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>>> "Drew Adams" <drew.adams@oracle.com> writes:

>>> This is the problem!  Macros shouldn't return a _list_, they should
>>> return a _form_.  If you write a macro that returns a list, or you
>>> use it so that it returns a list, that is not a valid form, then it
>>> is not good style, even if you catch up.

>> Is that right?  I think you should be required to justify this
>> assertion of "good style".  If that "good style" really is good style,
>> then the whole of cc-langs.el (which uses intense macro magic to
>> generate data structures with both compile-time and run-time
>> behaviour) is attrocious style.

> If that was the case, yes, I would think so.  Macros are designed to
> generate code, not other data.

I'm no lisp guru, but I must disagree strongly with this.  What is code,
what is data?  Surely they are essentiallty the same, particularly in
lisp.  You would hold that a macro which generates a font-lock-defaults
structure (so as to reduce the tedium of doing it by hand) is an abuse of
the macro idea, would you?

> If you are generating general data, then using functions will be easier
> and clearer.

If it's possible.  But if this were the case, using functions to generate
"code" would be easier and clearer, too.

> But cc-langs.el only defines four macros and they all generate
> perfectly good lisp code.

Any macro, once debugged, generates "perfectly good" lisp code.  I don't
understand where this notion of "perfectly good" comes from.

>> Fact is, though, it allows a simple tabular writing of constants which
>> vary between C, C++, java, ....  Kudos to Martin Stjernholm, who wrote
>> it.

> Unfortunately, most of emacs lisp code is bad code.  Functions one
> kilometer long, chained with one or more others one kilometer long.
> Copy-and-pasted chunks instead of abstracting it away.  Etc.

I can't disagree with that, sadly.  However I think Emacs's code base is
better than a typical 25 yo application still under development (if there
is such a beast).

> Now of course, I had a peek at code that had bugs or missing features
> in the first place.  Perhaps the good quality emacs lisp code I hadn't
> a peek at because it worked well enough so I didn't need to.

Perhaps.

>>> Because it is a better style.  It avoids abusing the ifdef macro.

>> Where does this notion of "abuse" come from?  What is its rationale?
>> (This is a genuine question.)

> The general contract of a macro is that it returns valid forms.

Sorry, Pascal, you're just restating the same thing again, not answering
my question.  Why should I accept this "general contract of a macro"?  I
haven't signed it.  ;-)  Is there some respected Lisp guru who says this?
What would this guru say about the macro which generates a
font-lock-defaults structure?

> In all fairness, ifdef does return valid forms, when provided valid
> forms as argument.

> (defmacro ifdef (expr &rest body)
>   (and (eval expr) `(progn ,@body)))

That version of ifdef is ugly because it contains an obtrusive `progn'.
The version I used doesn't.  There is no guarantee that a lisp compiler,
particularly the Emacs lisp byte compiler, is going to optimise away this
unnecessary artifact.  It seems this `progn' is there purely to satisfy
the (as yet unsubstantiated) injunction to return only "perfectly good"
lisp forms.

> The fact that such a macro call embedded in another form building form
> that processes it properly doesn't mean that it is not bad style: it
> has to do something special to the result of ifdef to make it work.
> If you extract that ifdef call to run it at the repl, it just cannot
> work.

Yes.

-- 
Alan Mackenzie (Nuremberg, Germany).



  reply	other threads:[~2009-11-24 10:45 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 [this message]
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
     [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

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

  git send-email \
    --in-reply-to='hegdgc$18ah$1@colin2.muc.de' \
    --to=acm@muc.de \
    --cc=help-gnu-emacs@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.