[plt-dev] syntax/module-reader and #%module-begin

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Nov 30 14:02:25 EST 2009

This sounds like a good idea.

The special treatment of a single form in a module body allows

 (module m name (#%module-begin ..))

to expand to itself, instead of

 (module m name (#%module-begin (#%module-begin ..)))

We could have defined `module' in other ways so that a module can
expand to itself, and maybe some of the other ways would have been
better. In any case, that's not a concern at the `#lang' level, so I
think it's fine for `syntax/module-reader' to add `#%module-begin'.

At Mon, 30 Nov 2009 13:14:29 -0500, Carl Eastlund wrote:
> Modules have this weird property: they behave differently if they have
> exactly one element in their body, than if they have zero elements, or
> two or more elements.  They expand that body element looking for
> #%module-begin.  If they have zero, or two or more, elements, they
> wrap those elements in #%module-begin.  The #%module-begin form does
> "most of the work" of expanding modules, so in the one-element-only
> case, there is a period of expansion during which #%module-begin is
> "not at the helm".  I bring this up because it caused a problem for
> Stevie (resulted in a bug report about #lang scheme/signature, in the
> case where a module contains precisely one form that is a use of
> "contracted").
> Most of our #langs are written with syntax/module-reader, which reads
> in a bunch of forms and wraps them in (module foo lang <FORM> ...).
> The problem above would go away if instead it wrapped the forms in
> (module foo lang (#%module-begin <FORM> ...)).  The only thing this
> gives up is the ability to fill in a custom #%module-begin, but... who
> does that, and why would one?
> Is it sensible to change syntax/module-reader to do this?  Or if not
> in general, is it worth adding a "#:add-module-begin" flag to
> syntax/module-reader to individual language authors can choose this
> behavior without having to implement it?
> Carl Eastlund
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-dev

Posted on the dev mailing list.