From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Is it possible for a macro to expand to nothing?
Date: Sat, 28 Nov 2009 13:57:44 +0100 [thread overview]
Message-ID: <87ljhqyfg7.fsf@tux.homenetwork> (raw)
In-Reply-To: 874oof54k9.fsf@galatea.local
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> Alan Mackenzie <acm@muc.de> writes:
>
>> Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>>> Tim X <timx@nospam.dev.null> writes:
>>
>>>> On the other hand, Alan's arguments also have merit. If a macro can be
>>>> useful in generating something other than a form that can be
>>>> evaluated, such as a data structure and can do so in a way that is
>>>> cleaner/simpler or just easier to understand than doing the same using
>>>> functions, then it would make sense. His examples from the C modes
>>>> seem to be a case in point.
>>
>>
>>> Perhaps Alan's problem with functions comes from the confusion between
>>> backquote and macros. Since backquote (and , and ,@) are often used in
>>> macros, some people believe they can be used only in macros, and that
>>> they ARE what macros are.
>>
>> Er, do I actually have a problem with functions? But no, I don't suffer
>> that particular confusion between backquotes and macros, and have indeed
>> used backquote when there hasn't been a macro within zeptoparsecs.
>>
>>> Far from it! I don't know any language more orthogonal than lisp.
>>
>> Maybe not, but even lisp only gets to about 89 degrees. It is missing an
>> operator which does the same as ,@ outside backquote. This is one of the
>> lacks which makes it so difficult to write an equivalent of C's #if.
>
> Yes, emacs lisp is missing reader macros. In Common Lisp there's #+,
> #- and #., and reader macros may return 0 object.
A little note about #., it have emacs equivalent `eval-when-compile':
,----[ That is the CL version ]
| -- Special Form: eval-when-compile forms...
| The FORMS are evaluated at compile-time; at execution time, this
| form acts like a quoted constant of the resulting value. Used at
| top-level, `eval-when-compile' is just like `eval-when (compile
| eval)'. In other contexts, `eval-when-compile' allows code to be
| evaluated once at compile-time for efficiency or other reasons.
|
| This form is similar to the `#.' syntax of true Common Lisp.
`----
I don't know the #- and #+ macros, what are they for?
>
>>> Backquote can be used in a function to build a s-exp (including part of
>>> a form) as it can be used anywhere.
>>
>>> Therefore it is really not easier to use macros to generate parts of a
>>> form than function.
>>
>> It is if you need "side effects", like c-lang-defconst and friends do.
>
> Well, I'm not sure about emacs, but in the case of Common Lisp, you
> have to be careful with side effects in macros, because it is not
> specified how many times, and when, macro functions are called.
>
> I'd say that with emacs you at least have the same problem if you load
> and/or eval the contents of a file and then you byte-compile it, the
> macros may be executed twice.
>
> So that's one more difficulty you have to cater to with macros, that
> you don't have with functions.
>
>
>> [ Stuff read and appreciated. My brain's not up to it so early in the
>> morning].
>>
>>> If you wanted to use macros, in addition to the complexity of having
>>> to use macroexpand to use it, you would have the difficulty of passing
>>> the parameters, since a macro gets it's parameters from the source
>>> form. In the case of a function, you have the choice to quote or not
>>> to quote the parameters, with macros they're always quoted for you.
>>
>> In the case of a function, you've GOT to quote, which can get very
>> tedious in some circumstances. That's probably the reason that Martin
>> Stjernholm wrote c-lang-const etc. as macros.
>
> Read again my example, I hadn't to quote the arguments to the function
> because they weren't the literal arguments, but variables containing
> the arguments, because the function was called from another function
> or macro (macro in this case) who got them as parameter.
>
> If you had to forward arguments to a macro, it would be much more
> complicated. Then you would have to use macroexpand.
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
next prev parent reply other threads:[~2009-11-28 12:57 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 [this message]
[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
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=87ljhqyfg7.fsf@tux.homenetwork \
--to=thierry.volpiatto@gmail.com \
--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.
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).