help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About `macroexpand'


From: Filipp Gunbin
Subject: Re: About `macroexpand'
Date: Sun, 30 Dec 2012 11:06:46 +0400
User-agent: Gnus/5.1299999999999999 (Gnus v5.13) Emacs/24.2 (cygwin)

On 30/12/2012 09:35, Xue Fuqiao wrote:

> On Sun, 30 Dec 2012 07:50:45 +0400
> Filipp Gunbin <fgunbin@fastmail.fm> wrote:
>
>> The comparison doesn't make any sense and what
>> is actually overwritten is the local value of `variable'.
>
> I still don't understand.  I tried this:
> (defmacro t-becomes-nil (variable)
>   (list 'if (list 'eq variable t)
>       (list 'setq variable nil)))
> (setq foo t)
> (macroexpand '(t-becomes-nil foo))
>
> But it returns (if (eq foo t) (setq foo nil)))
> What's the difference between these two macros?

This version is correct because it returns a form which can be
evaluated. 

The difference between your first and second version is that the first
does the (incorrect) computation itself (so macroexpand doesn't return
anything) and the second returns the form (and macroexpand shows it)
which can be in turn evaluated - and that is a correct macro.

The backquote in my example is just a special syntax which helps to
avoid complex `(list ...)' constructs with lots of quoting like those
you used.

-- 
Filipp Gunbin



reply via email to

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