[R6RS] Internal DEFINE vs. macros

Michael Sperber sperber
Fri Apr 22 12:04:11 EDT 2005


dyb at cs.indiana.edu writes:

> Chez Scheme processes body forms from left to right and adds macro
> definitions to the compile-time environment as it proceeds.  [...]
> In both systems, define rhs expressions are expanded, along with the
> body expressions that follow the definitions, only after the set of
> definitions is determined.

To me, the result is a confusing mixture of an operational and
declarative approach to macro expansion: The first pass is sequential
and thus sensitive to the ordering of the definition, but the
following macro expansion of the right-hand sides and body expressions
is (largely?) insensitive to them.

Consider this example:

(let ((x 10))
  (let-syntax ((foo (syntax-rules (x)
		      ((foo x d)
		       (define d 'outer))
		      ((foo n d)
		       'inner))))
    (let ()
      (foo x y)            ; <---
      (define z (foo x y)) ; <---

      (define x 5)

      (list y z))))
=> (outer inner)

The first <--- marked expression (foo x y) expands into the *first*
case in the definition of FOO.  In the second <--- marked expression,
(foo x y) expands into the *second* case.  (It should be possible to
turn the screw even further by having macros expand into definitions
of variables that are relevant to the macro expansion itself.)

In Chez, changing the position of the definition of x affects the
expansion of the first (foo x y), but not the second.  (If I
understand Matthew correctly, he also wants to change PLT to behave
this way.)

This can be explained operationally in terms of the expansion
algorithm, but it seems difficult to come up with any declarative
intuition for it.  I certainly can't just go up through the nesting
levels and easily associate identifier occurrences with their
bindings.

-- 
Cheers =8-} Mike
Friede, V?lkerverst?ndigung und ?berhaupt blabla


More information about the R6RS mailing list