Next: Using Guile Modules, Up: The Guile module system
A Guile module can be thought of as a collection of named procedures, variables and macros. More precisely, it is a set of bindings of symbols (names) to Scheme objects.
An environment is a mapping from identifiers (or symbols) to locations, i.e., a set of bindings. There are top-level environments and lexical environments. The environment in which a lambda is executed is remembered as part of its definition.
Within a module, all bindings are visible. Certain bindings can be declared public, in which case they are added to the module's so-called export list; this set of public bindings is called the module's public interface (see Creating Guile Modules).
A client module uses a providing module's bindings by either accessing the providing module's public interface, or by building a custom interface (and then accessing that). In a custom interface, the client module can select which bindings to access and can also algorithmically rename bindings. In contrast, when using the providing module's public interface, the entire export list is available without renaming (see Using Guile Modules).
To use a module, it must be found and loaded. All Guile modules have a
unique module name, which is a list of one or more symbols.
Examples are (ice-9 popen)
or (srfi srfi-11)
. When Guile
searches for the code of a module, it constructs the name of the file to
load by concatenating the name elements with slashes between the
elements and appending a number of file name extensions from the list
%load-extensions
(see Loading). The resulting file name is
then searched in all directories in the variable %load-path
(see Build Config). For example, the (ice-9 popen)
module
would result in the filename ice-9/popen.scm
and searched in the
installation directories of Guile and in all other directories in the
load path.
Every module has a so-called syntax transformer associated with it.
This is a procedure which performs all syntax transformation for the
time the module is read in and evaluated. When working with modules,
you can manipulate the current syntax transformer using the
use-syntax
syntactic form or the #:use-syntax
module
definition option (see Creating Guile Modules).
Please note that there are some problems with the current module system you should keep in mind (see Module System Quirks). We hope to address these eventually.