[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.11.3 Using modules

Special Form: export symbol ...
Makes bindings of symbols in the current module available to modules that imports the current module.

Special Form: export-all
Makes all bindings in the current module available to modules that imports it.

Special Form: import module-name ...
Makes all exported bindings in the module named module-name available in the current module. The named modules should exist when the compiler sees this special form.

Note that imports are not transitive. The modules that module-names are importing are not automatically imported to the current module. This keeps modules' modularity; a library module can import whatever modules it needs without worring about polluting the namespace of the user of the module.

Macro: use name
A convenience macro that combines module imports and on-demand file loading. Basically, (use foo) is equivalent to the following two forms:
(require "foo")
(import foo)
That is, it loads the library file named "foo" (if not yet loaded) which defines a module named foo in it, and then import the module foo into the current module.

Although the files and modules are orthogonal concept, it is practically convenient to separate files by modules. Gauche doesn't force you to do so, and you can always use require and import separately. However, all modules provided with Gauche are arranged so that they can be used by use macro.

If a module is too big to fit in one file, you can split them into several subfiles and one main file. The main file defines the module, and either loads, requires, or autoloads subfiles.

If name contains periods `.', it is replaced to `/' in the file name.to be required, for example, (use foo.bar.baz) is expanded to:
(require "foo/bar/baz")
(import foo.bar.baz)
This is not very Scheme-ish way, but nevertheless convenient. (The alternative design is to use a list of symbols to represent hierarchical file/module configuration, as in Guile.)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html