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

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

RE: [External] : macros and macroexpand


From: Drew Adams
Subject: RE: [External] : macros and macroexpand
Date: Mon, 7 Aug 2023 14:28:42 +0000

> I have made a macro and know that they are supposed to return
> expanded code for use.  Still I cannot understand the need to
> call "macroexpand".  Should't the macro already perform the
> expansion ?

This was amply explained in the answers
to your question when you posted in to
emacs.SE:

https://emacs.stackexchange.com/q/78347
____

In sum (repeating), the Lisp interpreter
evaluates sexps, including macro calls.

When it evaluates a macro call, it first
expands it according to the macro body
(which is effectively a sexp-to-sexp
pure function, regardless of how it's
implemented).  This is _rewriting_ code.

After expanding the macro call, i.e.,
replacing it with a different sexp, the
interpreter evaluates that sexp (which
returns the result of that evaluation).
____

The byte-compiler just _expands_ macro
calls, then byte-compiles the expansions.
That is, byte-compilation doesn't also
_evaluate_ the result of macro expansion.
Evaluation is done when the byte-compiled
code is evaluated/interpreted.
____

A macro call is a particular kind of
sexp, of course: it's a list with a
symbol as car, that is, it looks to Lisp
like a function call.  (There are also
symbol macros, which act similarly, but
on symbols not lists.)
____

You've been told all of this a few times
now.  If there's some particular part of
it that you don't understand then you
should ask only about that part.  Instead,
your MO is to broadcast the same question
multiple times to multiple places.

I can understand your wanting to get
different opinions, but your understanding
(which does progress) isn't reflected in
narrower questions.  Why is that?

reply via email to

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