[plt-scheme] Modules and extensions (yes, again)
At Sat, 19 Apr 2003 17:11:10 -0400, "Pedro Pinto" wrote:
> I would like to be able to create modules that use my custom resolver,
> i.e.
>
> (module my-module
> mzscheme
>
> (require (library "my-library"))
>
> (provide ...))
>
> This of course does not work since the resolver is not installed yet.
> But how can I install it *before* the module's require clause is
> evaluated?
Setting the module-name resolver essentially defines a new dialect of
`module'. If you have a closed world and control all of the code,
that's fine. But it's no good if you want to give modules to others to
incoporate into other programs.
Maybe I shouldn't have suggested the module-name resolver in the first
place. I suggested it because of your original description of the
problem:
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.
This doesn't fit into the current model of PLT modules. In the current
model, a program is a sequence of module declarations. In the model you
have implemented, a program consists of some things that get converted
to module declarations on demand.
This leaves us with a couple of possibilities that I see:
* You don't run your code in plain MzScheme, but only in your extended
dialect of MzScheme.
* Instead of using `load-library' on file "foo" to generate a module,
you create an actual module for each "foo", say "foo-wrap.ss":
(module foo-wrap mzscheme
(require (lib "convert-foo-to-scheme.ss" "ppinto"))
(include-library "foo"))
where "convert-foo-to-scheme.ss" defines `include-library'. The
`include-library' macro could expand to definitions + provides of
the form
(define (v1 ... vn)
(load-library "foo"))
(provide v1 ... vn)
The revised `load-library' returns multiple values or the module's
content, instead of declaring a module. (The `include-library'
macro must do some of the work of the old `load-library' to figure
out what the exports should be.)
Option 2 looks promising to me, but I don't know enough about your
`load-library' to be sure.
Matthew