[plt-scheme] how many times macros are defined?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri May 1 07:36:58 EDT 2009

At Thu, 30 Apr 2009 23:22:26 -0700 (PDT), Michele Simionato wrote:
> #!r6rs
> (import (rnrs) (for (only (rnrs) begin lambda display) (meta 2)))
> (define-syntax m
>   (let ()
>     (define-syntax m2
>       (begin
>         (display "at metalevel 2\n")
>         (lambda (x) "expanded-m\n")))
>     (define _ (display "at metalevel 1\n"))
>     (lambda (x) (m2))))
> (display (m))
> If I run this script in PLT I get:
> $ plt-r6rs meta2.ss
> at metalevel 2
> at metalevel 2
> at metalevel 1
> expanded-m

The current version prints "metalevel 2" only once. I don't remember
when this changed, but it was before version 4.1.4 (and the current
version is 4.1.5).

Older versions used to expand sets of internal definitions to a
`letrec-syntaxes+values' form. While processing internal definitions
for that conversion, transformer expressions would get evaluated. Then,
the transformer expressions would be evaluated again as part of the
generated `letrec-syntaxes+values' form. We changed the macro expander
to instead keep the results from the first evaluation.

Posted on the users mailing list.