Here's an updated version of my report on the macro experiment:
http://www.cs.utah.edu/~mflatt/scope-sets-2/
The main change is section 3, which presents a different solution than
before for the problem of using a macro in the same context where the
macro is defined. The old solution didn't work for a variant of the
example where both the macro definition and its use are
macro-introduced:
(define-syntax-rule (gen)
(begin
(define-syntax identity
(syntax-rules ()
[(_ misc-id)
(lambda (x)
(let ([misc-id 'other])
x))]))
(identity x)))
(gen)
With the old approach, `(gen)` would get a use-site scope, but
`(identity x)` wouldn't, and so the `x` provided to `identity` would
still capture (or create an ambiguous binding for) the `x` introduced
by `identity`. The new approach solves that problem by tying the
use-site scope to a macro invocation --- essentially symmetric to the
introduced-by-macro scope for a macro invocation --- instead of the
entire definition context. Some extra bookkeeping is needed to enable
macros that expand to definitions of use-site identifiers, but I think
it holds together.
This approach pushes a little more complexity into macros like `class`
and `unit` that manipulate definition contexts, but mostly they just
apply a new `syntax-local-...` function to identifiers that will be
moved into binding positions. We don't have a lot of those macros, and
adjusting them has been easy.
I've updated the "scope" branch at
https://github.com/mflatt/racket. To
make the main distribution build, I've had to change various packages
in ways that aren't backward-compatible; I've forked the following
repos and given them "scope" branches at my GitHub account:
compatibility
drracket
r5rs
redex
compiler
macro-debugger
racklog
scribble
Authors and maintainers of those repos might want to check the kinds of
changes I'm having to make.
I still don't recommend trying to run the new macro expander, yet.
Although `raco setup` now builds all bytecode without error, running
and building documentation doesn't yet work, mostly because the story
on top-level evaluation is not yet right (I think).