[plt-scheme] module-begin

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Tue Jun 27 09:31:40 EDT 2006

I am experimenting with a compiler from "from" to "to".
The plan is to let the syntax transformer for #%module-begin
in "from" do all the work and expand its body into
the "to" language.

Consider the minimal example, a "to" language
supporting nothing but datums:

   (module to mzscheme
     (provide #%datum))

Now I want

   (module foo from
     1)

to expand into something equivalent of

   (module foo to
      1)

A first attempt:

(module from mzscheme
   (provide (rename from-module-begin #%module-begin))

   (define-syntax (from-module-begin stx)
     (syntax-case stx ()
       [(_ E ...)
        #`(#%module-begin
             (require to)
             E ...)])))

This gives the error:

   compile: bad syntax; literal data is not allowed, because no #%datum
   syntax transformer is bound in: 1

I can fix the problem by importing and exporting bindings from
"from" in "to":

(module from mzscheme
   (provide (rename from-module-begin #%module-begin))

   (require (prefix to- to))
   (provide (rename to-#%datum #%datum))

   (define-syntax (from-module-begin stx)
     (syntax-case stx ()
       [(_ E ...)
        #`(#%module-begin
             E ...)])))

But that solutions requires me to change code in "from" everytime I add
new constructs in "to".

Is there a more elegant solution?

-- 
Jens Axel Søgaard




Posted on the users mailing list.