[plt-scheme] Scheme Sublanguage

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Oct 26 05:03:51 EDT 2005

Hi Paulo

>  (provide
>           define
>           if
>           zero?
>           1+
>           1-))
>Then I tried to use this:
>(module test basic-language
>  (define x 1)
>  )
>But I'm getting
>module: no #%module-begin binding in the module's language in: (module
>test basic-language (define x 1))
If you try to expand the test module you get:

  > (expand #'(module test (file "c:/Documents and 
                       (define x 1) ))
  (module test (file "c:/Documents and 
    (#%plain-module-begin (require-for-syntax mzscheme)
      (define-values (x) (#%datum . 1))))

So the test module has an implicit #%plain-module-begin around the body. 
The docs say:

   The mzscheme module binds #%app, #%top, and #%datum as regular 
   top-level variable reference, and implicit quote, respectively. A 
module can export
   different transformers with these names to support languages 
different from conventional Scheme.

  In addition, #%module-begin is used as a transformer for a module 
body. A #%module-begin is
  implicitly added around a module body when it contains multiple 
S-expressions, or when the
  S-expression expands to a core form other than #%module-begin or 
  the lexical context for the introduced #%module-begin identifier 
includes only the exports of the
  module's initial import. After such wrapping, if any, and before any 
expansion, an
  'enclosing-module-name property is attached to the module-body syntax 
object; the property's
  value is a symbol for the module name as specified after the module 

  The mzscheme module binds #%module-begin to a form that inserts a 
for-syntax import of
  mzscheme, so that mzscheme bindings can be used in syntax definitions. 
It also exports
  #%plain-module-begin, which can be substituted for #%module-begin to 
avoid the
  for-syntax import of mzscheme. Any other transformer used for 
#%module-begin must
   expand to mzscheme's #%module-begin or #%plain-module-begin.

That is, all you need to do is to provide #%module-begin in basic-language.

  When an expression is fully expanded, all applications, top-level 
variable references, and literal
  datum expressions will appear as explicit #%app, #%top, and #%datum 
forms, respectively. Those
  forms can also be used directly by source code. The #%module-begin 
form can never usefully
  appear in an expression, and the body of a fully expanded module 
declaration is not wrapped
  with #%module-begin; instead, it is wrapped with #%plain-module-begin.

Along with #%app, #%top, and #%datum. Of course you can define your own 
versions of these as my-app, my-top and my-datum and provide (renamed) 
versions of
these. E.g. you can let my-datum check that the literal is an integer.

See also the lambda-calculus example in the docs.

Jens Axel Søgaard

Posted on the users mailing list.