next up previous contents index
Next: Usage inference and the Up: 3. System Description Previous: 3.3 File Names and   Contents   Index


3.4 The Module System of XSB

XSB has been designed as a module-oriented Prolog system. Modules provide a small step towards logic programming ``in the large'' that facilitates large programs or projects to be put together from components which can be developed, compiled and tested separately. Also module systems support the principle of information hiding and can provide a basis for data abstraction. The module system of XSB is file based - one module per file - and flat - modules cannot be nested. In addition, XSB's module system is to some extent atom-based, where any symbol in a module can be imported, exported or be a local symbol, as opposed to the predicate-based ones where this can be done only for predicate symbols 3.3.

By default, files are not treated as modules. In order for a file to be treated as a module, it must contain one or more export declarations, which specify that a set of symbols appearing in that module is visible and therefore can be used by any other module. In XSB, the module name is equal to the base file name in which the module is defined. Any file (either module or not) may also contain import declarations, which allow symbols defined in and exported by other modules to be used in the current module. In addition, a module can also contain local declarations, which specify that a set of symbols are visible by this module only, and therefore cannot be accessed by any other module. Export, local, and import declarations can appear anywhere in the source or header files and have the following forms:

The module system of XSB is file based (one module per file), atom based (where all non-predicate symbols are normally assumed to be global to all modules), and flat (modules cannot

:- export $sym_1$, ..., $sym_l$.

:- local $sym_1$, ..., $sym_m$.

:- import $sym_1$, ..., $sym_n$ from $module$.

where $sym_i$ has the form $functor/arity$, and $module$ is a module name.

We note that only exported symbols can be imported; for example importing a local symbol will cause an environment conflict error when the file referred to by the import statement is loaded. When a non-module file is loaded, its predicates and symbols are loaded into the module usermod, which is the working module of the XSB interpreter. Dynamically asserted code is also loaded into usermod.

For modules, the base file name is stored in its byte code file, which means that if the byte code file is renamed, the base file name is not altered, and hence may cause confusion to the user and/or the system. However, byte code files generated for non-modules can be safely renamed.

In order to understand the semantics of modules, the user should keep in mind that in a module oriented system, the name of each symbol is identified as if it were prefixed with its module name (equivalently its base file name), hence two symbols of the same $functor/arity$ but different module prefixes are distinct symbols. Currently the following set of rules is used to determine the module prefix of a symbol:

The following facts about the module system of XSB may not be immediately obvious:



Subsections
next up previous contents index
Next: Usage inference and the Up: 3. System Description Previous: 3.3 File Names and   Contents   Index
Terrance Swift 2007-10-05