[plt-scheme] Scheme Sublanguage

From: Paulo Jorge Matos (pocmatos at gmail.com)
Date: Wed Oct 26 05:11:31 EDT 2005

Thanks a lot for the help. I checked the lambda example previously but
didn't quite get it. I forgot to try to expand. :D


Paulo Matos

On 26/10/05, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
> 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
> Settings/js/Dokumenter/tmp/slettes/basic.scm")
>                        (define x 1) ))
>   (module test (file "c:/Documents and
> Settings/js/Dokumenter/tmp/slettes/basic.scm")
>     (#%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
> application,
>    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
> #%plain-module-begin;
>   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
> keyword.
>
>   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
> restricted
> 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
>
>
>
>
>
>
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


--
Paulo Jorge Matos - pocm at sat inesc-id pt
Web: http://sat.inesc-id.pt/~pocm
Computer and Software Engineering
INESC-ID - SAT Group


Posted on the users mailing list.