[plt-scheme] Modules and extensions (yes, again)
Hi there,
I posted here last week with question on modules and extensions.
Basically my question was how to use require to load a module which was
created by an extension with a name unknown until runtime. Matthew was
kind enough to point me to the `current-module-name-resolver' parameter.
I tried that with mixed results. This is what I did:
(define (my-resolver path x y)
(define standard-resolver
(current-module-name-resolver))
(if (and (pair? path)
(eq? (car path) 'library))
(my-create-module)
(standard-resolver path x y)))
(current-module-name-resolver my-resolver)
Where my-create-module is part of an extension:
Scheme_Object *myCreateModule (int argc, Scheme_Object **argv)
{
Scheme_Object *moduleSymbol =
scheme_intern_symbol("my-module");
Scheme_Env *env =
scheme_primitive_module(moduleSymbol,
scheme_get_env(scheme_config));
// add some definitions here
.
.
.
scheme_finish_primitive_module(env);
return moduleSymbol;
}
The problem with this is that:
(require (library '()))
ends up invoking my-resolver (and myCreateModule) twice (although it
otherwise works as intended).
What I am missing here?
Thanks in advance,
-pp
At Sat, 12 Apr 2003 23:02:02 -0400, "Pedro Pinto" wrote:
> My extension provides a function, load-library, which when invoked
> will load a text file and based on the contents of the that file
> create a new module containing a set of bindings. The module name is
> dependent on the contents of said file and is returned by
> load-library.
>
> So how can I import the bindings created?
>
> I tried
>
> (require (load-library "mylibrary"))
>
> which of course does not work since what is returned is a module name
and
> not a file.
You'll probably have to change the module-name resolver to recognize
`load-library'. The moudle-name resolver is set through the
`current-module-name-resolver' parameter.
Matthew