[Top][All Lists]

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

Re: Compiling a recursive macro

From: Michael Heerdegen
Subject: Re: Compiling a recursive macro
Date: Thu, 11 Jun 2020 23:27:21 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Stefan Monnier <> writes:

> > That suggests to me that you can't compile any recursive macro.
> Depends what you mean by "recursive macro".
> What this prevents is to use a macro inside the definition of a macro.

Which means: the macro is not allowed to be used to generate the
expansion.  But it may appear in the expansion.

> Most cases of "recursive macros" instead just returns code which
> itself uses that macro.
> [...]
> This works just fine (and may inf-loop, of course).

That's indeed the most common problem in this area I think.

@Douglas: Often it helps me to remember the macro expander as a normal

You can literally rewrite a macro definition

(defmacro my-macro (args...)

using one function call as macro body instead:

(defmacro my-macro (args...)
  (my-macro-expander args...))


(defun my-macro-expander (args...)

where body... is the same as above in the defmacro.

Keeping that in mind, the answer to your question is more obvious, and
practically you can use the above transformation to trace or edebug
`my-macro-expander' to see what happens when the macro is actually
expanded somewhere.


reply via email to

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