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

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Mon Nov 30 13:14:29 EST 2009

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

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

Posted on the dev mailing list.