[Top][All Lists]

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

Re: Macro expansion: Why doesn't the invoked macro see (let (variables))

From: Alan Mackenzie
Subject: Re: Macro expansion: Why doesn't the invoked macro see (let (variables))from the invoking one?
Date: Fri, 10 Feb 2012 16:58:04 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

On Thu, Feb 09, 2012 at 09:23:55PM -0800, PJ Weisberg wrote:
> On Wed, Feb 8, 2012 at 12:09 PM, Alan Mackenzie <address@hidden> wrote:

> > I think you're right.  Ah well.  I learnt this afternoon that quoting a
> > macro invocation

> >    '(foo-macro)

> > doesn't stop it being expanded.  I don't think that's in the elisp
> > manual.

> Of course it isn't, because it's not true.  Try it yourself:

> (defmacro foo-macro ()
>   '(message "Foo macro's code has run!"))

> (defmacro bar-macro (one two)
>   `(list ,one '(foo-macro) ,two))

> If you evaluate:
> (bar-macro "Hello" "World")

> You get
> ("Hello" (foo-macro) "World")

> Whereas if you changed bar-macro to:
> (defmacro bar-macro (one two)
>   `(list ,one (foo-macro) ,two))

> you would get:
> ("Hello" "Foo macro's code has run!" "World")

> Likewise, (foo-macro) evaluates to "Foo macro's code has run!" (and
> prints the message), but '(foo-macro) evaluates to (foo-macro),
> exactly as you would expect.

Hmmm.  I wish I could remember exactly what I saw when playing around.
It was something involving macroexpand and a backquote.

Ah well, I'll come across it again, sometime.

Thanks for the correction.

> -PJ

Alan Mackenzie (Nuremberg, Germany).

reply via email to

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