[plt-scheme] problem w/ namespace-require
--- Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> The following code produces #t when run at the (module-language)
> prompt.
>
> (begin
> (namespace-require '(prefix foo: mzscheme))
> (namespace-require 'mzscheme)
> (display (module-identifier=? (syntax +) (syntax foo:+))))
>
> But the following module, when run in the module language, prints
> #f:
>
> (module foo mzscheme
> (begin
> (namespace-require '(prefix foo: mzscheme))
> (namespace-require 'mzscheme)
> (display (module-identifier=? (syntax +) (syntax foo:+)))))
>
> Why are these different, and what do I need to do to get the second
> to produce #t?
The namespace-require forms within the module affect the current
namespace--they have no effect on the module at all. The syntax forms
on the next line are given the lexical context information from the
module, where + is imported from mzscheme and foo:+ is unbound.
If you want to talk about the names bound in the *module*, try this:
(module foo-mod mzscheme
(require (prefix foo: mzscheme))
(require mzscheme)
(display (module-identifier=? (syntax +) (syntax foo:+))))
If you want to talk about the names in the current namespace, try
this:
(module foo-ns mzscheme
(namespace-require '(prefix foo: mzscheme))
(namespace-require 'mzscheme)
(display (module-identifier=?
(namespace-symbol->identifier '+)
(namespace-symbol->identifier 'foo:+))))
Here I used namespace-symbol->identifier instead of syntax, because
you don't want the meaning of + and foo:+ with respect to "right
here" (which is what syntax does), but rather the meaning in the
current namespace.
Ryan
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail