[R6RS] new syntax srfi draft, reference implementation

Michael Sperber sperber at informatik.uni-tuebingen.de
Thu May 18 14:33:46 EDT 2006

dyb at cs.indiana.edu writes:

> I'd be happy to include a more explicit discussion of the issues if you
> want to take a stab at it, but the referenced message appears to be more
> about local modules than internal definitions, and it also contains a
> misleading description of the expansion algorithm.  This could confuse
> people if referenced from the SRFI.

How about this:

Allowing `define-syntax' in local environments incurs subtle issues
with the interaction between shadowing and macro expansion.  For
example, inconcistencies arise between the behavior of internal
`define' and internal `define-syntax'.  As an example, consider the
following expression:

(let-syntax ((foo (syntax-rules ()
                    ((foo) 'outer))))
  (let ()
    (define a (foo))
    (define-syntax foo
      (syntax-rules ()
        ((foo) 'inner)))

As the right-hand side of the definition of `a' is expanded only after
the inner macro definition for `foo' has been collected, the result is 'inner.

Next, consider this expression:

(let-syntax ((foo (syntax-rules ()
                    ((foo ?x) (define ?x 'outer)))))
  (let ()
    (foo a)
    (define-syntax foo
      (syntax-rules ()
        ((foo ?x) (define ?x 'inner))))

Again, the first form in the let refers to a macro definition named
`foo', definitions for which occur in places analogous to the first
example.  However, this time (foo a) gets expanded before the inner
definition for the `foo' macro has been seen---and hence uses the
outer macro.  Consequently, this expression returns 'outer.

The semantics of expressions like these are highly sensitive to the
particular operational specification of macro expansion, and Scheme
implementations have historically used different such formulations.
Arguably, not many programs are sensitive to such differences, but
some are:


Similar issues already arise in the context of R5RS Scheme, but are
much harder to trigger there.  Internal `define-syntax' aggravates

Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

More information about the R6RS mailing list