[plt-scheme] Evaling syntax with module bindings

From: Lauri Alanko (la at iki.fi)
Date: Mon Jan 30 16:55:05 EST 2006

On Mon, Jan 30, 2006 at 01:58:01PM -0700, Matthew Flatt wrote:
> I'm pretty sure I disagree with you on this conclusion. It seems to me
> that the providing module should know how its exported identifiers are
> used (at least in terms of phase).

I have a thingie that converts syntax objects to other syntax objects,
the latter ones representing scheme code. It should be usable in two
ways: either the input is inlined into a scheme module in which case my
thingie runs as a normal syntax transformer during macro expansion. Or
then the input is parsed from a file at run-time, converted by my
thingie into code, and then evaled.

The thingie just converts syntax into syntax. It knows which modules
define the identifiers that are used in the generated code. Why should
it care about whether it is being run by a syntax transformer or by a
run-time program? It does the same thing in either case.

> Maybe you should compile a `module' expression instead of a top-level
> expression, and then evaluate the compiled module in a different
> namespace (with a different `a'). Is that possible in your case?

Certainly. I was only using the top-level since it looked like the
simplest example, I didn't realize that it caused extra difficulties.

Still, I don't quite understand what you are suggesting. Here's
some vague scrawling:

(module a mzscheme
(provide xa)
(define xa 42))

(module b mzscheme
(provide xb)
(require-for-template a)
(define xb #'(module d mzscheme (require a) (provide xd) (define xd xa))))

(module main mzscheme
(require b)
(define old-ns (current-namespace))
(define ns (make-namespace))
(namespace-require 'a)
(parameterize ((current-namespace ns))
  (namespace-attach-module old-ns 'a)
  (eval xb)
  (namespace-require 'd)
  (namespace-variable-value 'xd)))

(require main)

And this doesn't work, of course. If I change the require-for-template
to require, then it works, but the purpose here was to be able to
generate code for both phases. I don't understand why I should be
requiring anything in module b: isn't the expression xb completely
closed? This goes way over my head...


Posted on the users mailing list.