[plt-scheme] module-begin
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