Next: , Up: iklib modules   [Index]


6.36.1 Defining modules

Modules are defined with the module syntax and named modules are imported in the local context with the import syntax.

Syntax: module ?interface ?definition ... ?expression ...
Syntax: module ?name ?interface ?definition ... ?expression ...

Define a new local module. The first form defines an anonymous module, while the second form defines a named module called ?name, which must be an identifier.

?interface is a list of identifiers selecting syntactic bindings from this module to be exported; every listed identifier must be bound in this module’s ?definition, otherwise an error is raised.

?definition is a set of syntactic binding definitions like the one that may appear at the beginning of a let body, with the addition of import forms that may import syntactic bindings from libraries and other modules. ?expression is a set of expressions that is evaluated at module’s definition time. At run–time: the ?expression forms are always evaluated right after the right-hand sides of the ?definition forms and before everything that comes after the module definition.

Modules “exist” only in the enclosing region, bindings exported from a module are not accessible outside of the enclosing region. Modules can be nested and import/export relations are possible according to the regions nesting hierarchy.

Bindings in the ?interface declared by anonymous modules are imported by default in the enclosing region: there is no need to use import. Bindings in the ?interface declared by named modules are visible only in regions that import the module; all the renaming facilities of the import syntax are available for modules.