emacs-devel
[Top][All Lists]
Advanced

[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: PJ Weisberg
Subject: Re: Macro expansion: Why doesn't the invoked macro see (let (variables))from the invoking one?
Date: Thu, 9 Feb 2012 21:23:55 -0800

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.

-PJ

Gehm's Corrollary to Clark's Law: Any technology distinguishable from
magic is insufficiently advanced.



reply via email to

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