Formally, module definition needs an “interface”, a “config” and
the body. An interface declares which bindings are exported,
and a config is either usually an
These special forms each create a new module with interface
interface and configuration config. The full syntax
of an interface is described in the next section.
defines an anonymous structure.
After configuring the module as specified, the sequence of forms body… is evaluated; it should include the definitions required by the interface that the module has promised to implement.
The config form is either a list of configuration clauses, or a single configuration clause. Each such clause must be of the following syntax:
clause -> (open name …) | (access name …)
Each name specifies the name of a module.
Always make it rule to open
rep structure. It’s because Librep
used to offer Scheme mimicry by importing
As described in the section
Module and File, it only
makes sense if a module is defined in a file with an appropriate
Here is an example module definition, defining a module named
test that exports two functions
(define-structure test (export foo bar) (open rep) (define (foo x) (* x 42)) (define (bar x y) (+ (foo x) (1+ y))))
It is also possible to export multiple views of a single underlying set
of bindings, by using the
define-structures form to create a
number of modules.
Create a module for each
(name interface) pair. The
module is called name and exports the interface defined by
The config and body… forms are as in
Here is a trivial example:
(define-structures ((foo (export foo both)) (bar (export bar both))) (open rep) (define both 1) (define foo 2) (define bar 3))
the underlying environment has three bindings. Each created module exports two of these.