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

From: Michele Simionato (michele.simionato at gmail.com)
Date: Fri May 1 02:22:26 EDT 2009

As some of you will know, I have been writing a series of articles
about
R6RS Scheme for a while (http://www.artima.com/weblogs/viewpost.jsp?
thread=251474).
Recently, I have started a cycle about the R6RS module system and
I am going to write something about the tower of metalevels.

My focus is on portability issues between different R6RS
implementations.

While I was working at an example of code running at metalevel 2
I have found a behavior of PLT Scheme which is quite unclear to me.
Here is the code:

#!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 puzzling thing for me is that I get the message "at metalevel 2"
twice, whereas I would expect to get it only once, when the inner
macro m2 is defined (Ikarus does so).
Can you share some light on what it is happening here?
TIA,

                Michele Simionato


Posted on the users mailing list.