[Top][All Lists]

[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" <address@hidden> 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__

reply via email to

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