For historical reasons, Gauche has three
import forms; the original
import, and the hybrid
Usually it is clear that the code is written in traditional Gauche
or in R7RS, and usage of
import is typically idiomatic, so there’s
not much confusion in practice. Only when you talk about
outside of code, you might need to specify which one you’re talking.
import is what we described
the previous section (see Traveling between two worlds back and forth).
It understands both of Gauche’s
So what you really need to know is the first two.
Gauche’s module system design is inherited from STk, and we’ve been
import for purely name-space level operation; that is,
it assumes the module you import from already exists in memory.
Loading a file that defines the module (if necessary) is
done by separate primitives,
require. In most cases one file
defines one module, and using that module means
require it then
import it (it’s so common that Gauche has a macro for it—
However, separating those two sometimes comes handy when you need
some nontrivial hacks. See Using modules, for the details of
R7RS leaves out the relation between modules (libraries) and files
in order to give implementation freedom. If necessary, its
must load a file implicitly and transparently. So R7RS’s
is semantically Gauche’s
import only appears at the beginning of the Scheme
scripts. It finds out whether the script is in the traditional Gauche
code or in the R7RS code. See Traveling between two worlds back and forth, for the details.
Now we’ll explain R7RS
[R7RS] Imports libraries specified by import-specs. What R7RS calls libraries are what Gauche calls modules; they’re the same thing.
R7RS libraries are named by a list of symbols or integers,
(scheme base) or
It is translated to Gauche’s module name by joining the symbols
by periods; so, R7RS
(scheme base) is Gauche’s
data.queue is available as
(data queue) in R7RS. To use those two libraries,
R7RS program needs this form at the beginning.
(import (scheme base) (data queue))
It works just like Gauche’s
use forms; that is, if the named
module doesn’t exist in the current process, it loads the file; then
the module’s exported bindings become visible from the current module.
(use scheme.base) (use data.queue)
(You may wonder what if R7RS library uses symbols with periods in them. Frankly, we haven’t decided yet. It’ll likely be that we use some escaping mechanism; for the time being you’d want to stick with alphanumeric characters and hyphens as possible.)
Just like Gauche’s
use, you can select which symbols to be
imported (or not imported), rename specific symbols, or add
prefix to all imported symbols. The formal syntax
of R7RS import syntax is as follows:
<import declaration> : (import <import-set> <import-set> ...) <import-set> : <library-name> | (only <import-set> <identifier> <identifier> ...) | (except <import-set> <identifier> <identifier> ...) | (prefix <import-set> <identifier>) | (rename <import-set> (<identifier> <identifier>) (<identifier> <identifier>) ...) <library-name> : (<identifier-or-base-10-integer> <identifier-or-base-10-integer> ...)