[plt-scheme] Some syntax issues

From: Lauri Alanko (la at iki.fi)
Date: Sat Aug 17 17:49:05 EDT 2002

On Thu, Aug 15, 2002 at 10:20:12AM -0700, Matthew Flatt wrote:
> > Is there any cleaner way of defining a
> > variable that is to be used only from a macro?
> I don't know. I hope so, but I haven't quite found it myself.

Here's one idea. We need a new construct: a traditional nested scoping
block akin to C++'s namespaces or ML's modules. It is in essence an
inner module declaration in which the definitions outside it are also
visible (as opposed to current PLT modules which do not see top-level
bindings). Nested modules would be useful for other things too, but here
we need just a special kind: an _anonymous_ one.

In addition, we need set-syntax!. This shouldn't be a very big deal,
since syntactic bindings are already mutable, as demonstrated by

So now we can define a macro that refers to a unique variable simply as:

(define-syntax my-macro #f)
   (define my-variable (whatever))
   (set-syntax! my-macro (lambda (stx) #'(do-something-with my-variable))))

Since each anonymous-inner-module has its own scope, it's no big deal
that we use the same identifier for my-variable multiple times.

I don't quite understand the module system well enough to say how these
inner modules should be implemented, but I don't see any conceptual
problems with them. Not yet, anyway. :)

Lauri Alanko
la at iki.fi

Posted on the users mailing list.