[plt-scheme] Syntax and namespaces

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Aug 29 09:59:47 EDT 2004

At Sat, 28 Aug 2004 00:16:11 -0700, Don Felgar wrote:
> Given this:
> 
>     (define x "The quoted expression is: ")
> 
> can I create something to this effect
> 
>     (define-syntax foo
>       (syntax-rules ()
>         ((_ path)
> 	 (begin
> 	  (display x)
> 	  (display 'path)
> 	  (newline)))))
> 
> in a different namespace?

I see several different answers, depending on exactly what you need.

 1. Put `x' and `foo' into a module, and only export `foo'. Then,
    wherever you import the module, `foo' is visible and `x' is not.

 2. If "different namespace" means using `make-namespace', then the
    `foo' as above can't work. A macro can only expand into uses of
    identifiers in the same namespace (or, more precisely, identifiers
    from modules instances in the same module registry).

    You might be able to create a 3-D macro (i.e., embed a procedure as
    "syntax") that bridges the namespaces.

 3. If you need to make sure that `x' isn't directly accessed in the
    new namespace (in the sense of `make-namespace'), but `x' should be
    accessible outside of a module in some old namespace, then there's
    a new solution in v299.14: you can export `x' with `protect', etc.

Probably there are more answers, too, but are any of these in the right
direction?

Matthew



Posted on the users mailing list.