[plt-scheme] macrophases

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Apr 7 09:50:11 EDT 2004

At Wed, 7 Apr 2004 02:05:23 -0700, "Bradd W. Szonye" wrote:
> However, the MODULE style also has significant costs. The transformers
> and the utility functions must reside in different modules. You can put
> the modules in the same file, but then they don't play nice with PLT's
> compilation and collection tools, which strongly prefer one module per
> source file. You can put the modules in different files, but that
> complicates source administration and hampers readability. The MODULE
> style would be much easier to use with tools that support multiple
> modules per file. (Some kind of preprocessor or literate programming
> tool might help; it's quite common to generate several intermediate
> files from a single literate-programming source file.)

I believe that `begin-for-syntax' is a better solution to this problem
than multi-`module' files.

With `begin-for-syntax', you could write

 (module m mzscheme
   (begin-for-syntax
    (define macro-helper ...)
    (provide macro-helper))
   (define-syntax macro ... #| use macro-helper |# ...)
   (define function ...)
   (provide macro function))

and then

 (require m)

would introduce `macro-helper' into the transformer environment, as well
as `macro' and `function' into the run-time environment.

> What's special about LET[REC]-SYNTAX that adds more levels to the
> compile-run hierarchy?

Nesting. A `let[rec]-syntax' form can appear in the right-hand side of
a `let[rec]-syntax' binding, which can itself appear in the right-hand
side of a `let[rec]-syntax' binding, etc.

In contrast, a `define-syntax' form must appear at the top level, so
nesting isn't possible. (If `define-syntax' is not at the top-level,
then it's really a `letrec-syntax' in disguise.)

Of course, nesting would also be possible with `begin-for-syntax'.

Matthew



Posted on the users mailing list.