[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is it possible for a macro to expand to nothing?
From: |
Pascal J. Bourguignon |
Subject: |
Re: Is it possible for a macro to expand to nothing? |
Date: |
Mon, 23 Nov 2009 21:21:36 +0100 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) |
"Drew Adams" <drew.adams@oracle.com> writes:
>> > (defmacro titi (fn)
>> > `(defun ,fn ()
>> > (setq bar 1)
>> > ,@(ifdef baz '((setq bar 2))))))
>> >
>> > Assuming that ifdef returns nil if baz is nil, that should
>> > give you (defun foo () (setq bar 1)). If baz is not nil,
>> > it should give you this:
>> >
>> > (defun foo ()
>> > (setq bar 1)
>> > (setq bar 2))
>>
>> Yes. Unfortunately, (ifdef baz '((setq bar 2))) doesn't produce a
>> valid form when baz is not nil.
>
> Huh? It produces the list ((setq bar 2)), assuming `ifdef' acts like `and'
> (`ifdef' is undefined AFAIK).
Yes. And ((setq bar 2)) is not a valid form. So it is not a good
idea, not a good style to call (ifdef baz '((setq bar 2))) and use its
result like that.
>> 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.
--
__Pascal Bourguignon__
- Re: Is it possible for a macro to expand to nothing?, (continued)
- Re: Is it possible for a macro to expand to nothing?, Pascal J. Bourguignon, 2009/11/27
- Re: Is it possible for a macro to expand to nothing?, Tim X, 2009/11/27
- Re: Is it possible for a macro to expand to nothing?, Pascal J. Bourguignon, 2009/11/27
- Re: Is it possible for a macro to expand to nothing?, Alan Mackenzie, 2009/11/28
- Re: Is it possible for a macro to expand to nothing?, Pascal J. Bourguignon, 2009/11/28
- Re: Is it possible for a macro to expand to nothing?, Thierry Volpiatto, 2009/11/28
- Message not available
- Re: Is it possible for a macro to expand to nothing?, Pascal J. Bourguignon, 2009/11/28
- Re: Is it possible for a macro to expand to nothing?, Pascal J. Bourguignon, 2009/11/24
- Message not available
- Re: Is it possible for a macro to expand to nothing?, Pascal J. Bourguignon, 2009/11/23
- RE: Is it possible for a macro to expand to nothing?, Drew Adams, 2009/11/23
- Message not available
- Re: Is it possible for a macro to expand to nothing?,
Pascal J. Bourguignon <=
- RE: Is it possible for a macro to expand to nothing?, Drew Adams, 2009/11/23
- Message not available
- Re: Is it possible for a macro to expand to nothing?, Pascal J. Bourguignon, 2009/11/23
- Message not available
- Re: Is it possible for a macro to expand to nothing?, Alan Mackenzie, 2009/11/23
Re: Is it possible for a macro to expand to nothing?, Jeff Clough, 2009/11/23