[CM] Snd 10.8
Kjetil S. Matheussen
k.s.matheussen at notam02.no
Sun Aug 9 07:22:15 PDT 2009
On Sun, 9 Aug 2009, Heinrich Taube wrote:
> Im expecting to see the "expanding foo macro!" message only one time.
> but maybe im confused!
> that is i thought the macro got expanded when 'define' did its work,
> not when i call the function.
>
> (define-macro (foo . args)
> (format #t "expanding foo macro!~%")
> `(list , at args))
>
> (define (usefoo a b c)
> (foo a b c))
>
> cm> (usefoo 1 2 3)
> expanding foo macro!
> (1 2 3)
> cm> (usefoo 1 2 3)
> expanding foo macro!
> (1 2 3)
> cm> (usefoo 1 2 3)
> expanding foo macro!
> (1 2 3)
> cm>
>
I'm pretty sure this is the common behavior for lisp interpreters.
I even think the common lisp standard require implementations
to evaluate the macros every time they are interpreted. (?)
Besides making it easier to give better debug trace plus
making it easier to redefine macros, this behaviour also
gives some interesting possibilities. My head hurts
a little bit now, but I think the whole rt compiling
system in rt-compiler.scm depends on macros to be expanded
during evaluation, although I'm not able to figure out how things
work right now.
But there are of course ways to optimize the macro expansion.
Guile, for instance, memoize expanded code, if I remember
correctly.
More information about the Cmdist
mailing list