[plt-scheme] 360.1

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Nov 20 16:58:07 EST 2006

MzScheme and MrEd are now version 360.1 in the SVN repository trunk.

The only change is an adjustment to macro expansion. Previously,
`local-expand' did not work when given an empty stop list and an
expression that contains local syntax definitions and uses:


`local-expand' now works reliably with an empty stop list.

The change in the expander (as suggested by Ryan Culpepper) is that a
locally bound identifier is expanded to an identifier that has no more
"marks" than its binding. This adjustment to the identifier's marks
preserves binding relationship in case the expression is later compiled
or re-expanded. Unlike the old `expand' technique of applying a global
"ignore extra marks" annotation after a full expansion, repairing marks
at the expansion of an identifier also works for local expansion --- as
long as the local expression is expanded completely.

 (define-syntax (s stx)
   (syntax-case stx () 
     [(_ x) (local-expand #'x (syntax-local-context) null)]))

 (s (let ([x 10]) 
      (let-syntax ([foo (lambda (stx) #'x)]) 
        (list foo))))
 ; => '(10)

You can still get `local-expand' to mangle an expression: provide a
non-empty stop list that doesn't include all binding forms but does
include forms that wrap uses of bindings. For example,

 (define-syntax (s stx)
   (syntax-case stx () 
     [(_ x) (local-expand #'x (syntax-local-context) 
                          (list #'list))]))

 (s (let ([x 10]) 
      (let-syntax ([foo (lambda (stx) #'(list x))]) 
 ; => out of context `x', because the `x' inside `(list x)'
 ;    was not expanded after `foo' was expanded

I think strange stop lists like this one make no sense in practice, and
they can create other problems in expansion (e.g., in contexts for
internal definitions). So, we may eventually change `local-expand' so
that it allows an empty stop list or a superset of the expression
forms, but not something in between.

Finally, I note that the change to the expander does not make
`expand-once' work any better than before, essentially because
`expand-once' is like using `local-expand' with a strange stop list.
Use the macro debugger in DrScheme, instead.


Posted on the users mailing list.