Gauche has a simple module system that allows modularized development of large software.
A higher level interface is simple enough from the user’s point
of view. It works like this:
When you want to use the features provided by module
foo
, you just need to say (use foo)
in your code.
This form is a macro and interpreted at compile time.
Usually it loads the files that defines foo
’s features,
and imports the external APIs into the calling module.
The use
mechanism is built on top of two independent
lower mechanisms, namespace separation and file loading mechanism.
Those two lower mechanisms can be used separately, although it is much more
convenient when used together.
The use
mechanism is not transitive; that is,
if a module B uses a module A, and a module C uses the module B,
C doesn’t see the bindings in A. It is because B and A is not in the
is-a
relationship.
Suppose the module A implements a low-level functionality and
the module B implements a high-level abstraction; if C is using
B, what C wants to see is just a high-level abstraction, and
doesn’t concern how B implements such functionality. If C wants
to access low-level stuff, C has to use
A explicitly.
There is another type of relationship, though. You might want to
take an exiting module A, and add some interface to it and provide
the resulting module B as an extension of A. In such a case,
B is-a A, and it’d be natural that the module that uses B can also
see A’s bindings. In Gauche, it is called module inheritance
and realized by extend
form.
The following sections in this manual describes modules in details.