[plt-scheme] namespace-variable-value missing?

From: Ryan Culpepper (ryan_sml at yahoo.com)
Date: Wed May 3 14:28:51 EDT 2006

--- Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
> 
> On Wed, 3 May 2006, Paulo J. Matos wrote:
> 
> > (module test mzscheme
> >
> > (require (lib "texpict.ss" "texpict"))
> >
> > (namespace-variable-value 'ht-append))
> 
> 
> Hi Paulo,
> 
> Odd.  I don't understand the documentation too, then --- I would
> have expected use-mapping? to let us get the imported module 
> variable.
> 
> Here's an example that appears to get at *ht-append*:
> 
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (module test mzscheme
>    (require (lib "texpict.ss" "texpict"))
>    (define my-ht-append
>      (namespace-variable-value
>       'ht-append
>       #t
>       (lambda () #f)
>       (module->namespace '(lib "texpict.ss" "texpict")))))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> but I don't yet understand why your example doesn't work yet.
> 
> Best of wishes!

The namespace-variable-value procedure uses the current namespace by
default.

The current namespace is unrelated to the lexical environment, and it
is unrelated to the namespace of the module where the call occurs. It
doesn't magically change according to what module a procedure call
occurs in.

Danny's code explicitly fetches the namespace for the module that
defines the variable it wants to look up.

Using require, define, etc at the top level affects the current
namespace, and that's why the original code works.

I don't know of a straightforward way to get the namespace that
corresponds to "this module". If you know an absolute module path
(like Danny's code used), you could use it. Otherwise, you can try
creating a module path with this-expression-source-directory and
this-expression-file-name, but beware if you try to create additional
abstractions on top of those.

Ryan



Posted on the users mailing list.