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

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

Re: Macro Expansion Inconsistency


From: John Mastro
Subject: Re: Macro Expansion Inconsistency
Date: Tue, 16 Dec 2014 13:46:30 -0800

Alexander Shukaev <haroogan@gmail.com> wrote:
> > Just consider when exactly the different parts of your macro are
> > evaluated. When is something that is quoted in the definition evaluated?
> > And when is something that is comma-escaped evaluated? Then look
> > carefully at what is quoted and what is comma-escaped. You'll see that
> > in the first version, something doesn't match.
>
>
> If I would want to think more myself I would not ask for help. Could you
> just explain if you know?

    (defmacro test (name)
      `(let* ((name ',name)
              (symbol (intern (concat "some" "-" (symbol-name name)))))
         ,symbol))
         ^^^^^^^

The comma operator causes something to be evaluated when the macro is
expanded, but the `symbol' binding doesn't exist until runtime (at which
time it exists where the macro expanded, not within the macro's body).

This is another version that will work (notice the lack of quoting):

    (defmacro test (name)
      (let ((symbol (intern (concat "some" "-" (symbol-name name)))))
        symbol))

---
john



reply via email to

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