[plt-scheme] checking my macro understanding.

From: Ryan Culpepper (ryan_sml at yahoo.com)
Date: Fri Feb 9 17:33:15 EST 2007

--- Matthew Flatt <mflatt at cs.utah.edu> wrote:

> At Thu, 8 Feb 2007 12:45:14 -0800, John Clements wrote:
> > Broadly, if I want to expand into a module form, I need to be
> careful  
> > to defeat hygiene wherever I want to embed code that refers to
> macros  
> > that are imported into the module.  Is this correct?
> Yes.
> Generally, I would discourage anyone from writing a macro that
> expands
> into `module'. Although expanding to `module' might make sense to
> implement a special kind of REPL, it's not going to play right with
> module loading via `require'. Also, you have to deal with the
> existing
> context on identifiers inserted by the macro, as in the example.

I've run into this problem even without module-producing macros, in
my test cases for the macro stepper. I can't use the #' notation for
the module declaration test data because it makes the modules expand
wrong. I use plain S-expressions instead, but then I lose the other
information like source locations.

Shouldn't the 'module' form automatically strip away the existing
lexical context of the module body? Would that break other
program-processing tools?

Actually, why isn't the renaming layer applied by 'module' working in
the original example anyway? It seems like the inner module
environment should simply shadow the outer module environment.


> >From an off-list discussion, it sounds like you're creating a
> reader
> extension that produces a `module' form. That's a perfectly good
> idea.
> For example, `#honu ...' is converted by the reader to `(module
> ...)'.
> Depending on how you implement such a reader, it may be tempting to
> generate parts of the reader's result using #' --- but don't do
> that.
> Syntax objects produced by a reader shouldn't have any lexical
> bindings. Instead, always create syntax objects with
> `datum->syntax-object' using #f as the first argument.
> Matthew
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.