[Top][All Lists]

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

Re: macros, procedure->macro

From: Marius Vollmer
Subject: Re: macros, procedure->macro
Date: 15 Jul 2002 22:48:38 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Dirk Herrmann <address@hidden> writes:

>   (define-macro (foo x) `(list ,(bar x) ,x))
>   (define-macro (bar x) `(* ,x ,x))
> will work, because the macro definition will not be expanded.

Careful, Dirk. :) The term 'macro definition' is not really helpful
here, I think.  On the lowest level, a macro can be thought of as an
ordinary function that is called during compilation.  In order to run
this function, the macros that it uses must be expanded, like in any
other function.  The literal data structures that are embedded in the
function are not expanded, of course (just as they aren't for any
other function).

However, a 'quasi-quote' form is not a literal data structure, while
'quote' is.  'foo' from above is equivalent to

    (define-macro (foo x) (list 'list (bar x) x))

Thus, the function of the 'foo' macro makes use of the 'bar' macro,
which therefore needs to be defined when the compiler macro-expands
'foo's function, which might be just after it reads it in.  Had it

    (define-macro (foo x) (list 'list '(bar x) x))

then '(bar x)' would be a literal data structure and the definition
for 'bar' would be needed when the 'foo' macro is expanded, which
happens probably after 'bar' has been defined.

(Dirk, I don't think you need this detailed lecturing, but I couldn't
stop myself.)

reply via email to

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