[plt-scheme] loading extension in a module

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Nov 30 08:05:13 EST 2004

At 29 Nov 2004 20:42:15 -0800, Ian Zimmerman wrote:
> Clearly, as the transcript in my post shows, when load-extension is
> called at the toplevel, it directly imports the new primitives into the
> toplevel namespace.  I just want to do the same thing _in a regular
> Scheme module_, i.e. make the C primitives be part of the module
> namespace.

To make an analogy, suppose that you had some Scheme top-level
definitions

 (define foo 17)
 (define bar 12)

Then, you could use `load' to get them into the top-level namespace.
But if you wanted to import the above definitions into a module, you'd
have to put the definitions into their own module, and use `require' to
import them.

The same is true for C-implemented code. Your extension currently works
with `load-extension' and creates top-level definitions. But if you
want the definitions to be imported into a module, then you need to
make the extension a module and import it with `require'.


Daniel sketched how to make your extension a module. When you compile
the module-ized C code, put it in a subdirectory 

  (build-path "compiled" "native" (system-library-subpath))

relative to "stat.ss". (If you use the --auto-dir flag in mzc, it will
put the file there.) Then change

  (load-relative-extension "plt_stat.so")

to 

  (require "plt_stat.ss")

and the .so will be imported into the module.

Matthew



Posted on the users mailing list.