Go to the first, previous, next, last section, table of contents.


The module system

Author(s): Daniel Cabeza and the CLIP Group.

Version: 1.5#118 (2000/4/19, 18:13:43 CEST)

Modularity is a basic notion in a modern computer language. Modules allow dividing programs in several parts, which have its own independent name spaces. The module system in Ciao [CH00b], as in many other Prolog implementations, is procedure based. This means that predicate names are local to a module, but functor/atom names in data are shared.

The predicates visible in a module are the predicates defined in that module, plus the predicates imported from other modules. Only predicates exported by a module can be imported from other modules. The default module of a given predicate name is the local one if the predicate is defined locally, else the last module from which the predicate is imported, having explicit imports priority. To refer to a predicate from a module which is not the default for that predicate the name has to be module qualified. A module qualified predicate name has the form Module:Predicate as in the call debugger:debug_module(M). Note that this does not allow having access to predicates not imported, nor defining clauses of other modules.

All predicates defined in files with no module declaration belong to a special module called user, and all are implicitly exported. This allows dividing programs in several files without being aware of the module system at all. Note that this feature is only supported for compatibility reasons, being its use discouraged. Many attractive compilation features of Ciao cannot be performed in user modules.

The case of multifile predicates (defined with the declaration multifile/1) is also special. Multifile predicates can be defined by clauses distributed in several modules, and all modules which define a predicate as multifile can use that predicate. The name space of multifile predicates is independent, as if they belonged to special module multifile.

Every user or module file imports implicitly a number of modules called builtin modules. They are imported before all other importations of the module, allowing thus redefining any of their predicates (with the exception of true/0) by defining local versions or importing them from other modules. Importing explicitly from a builtin module, however, disables the implicit importation of the rest (this feature is used by package library(pure) to define pure prolog code).

Usage and interface (modules)

Documentation on internals (modules)

DECLARATION: module/3:

Usage: :- module(Name,Exports,Packages).

DECLARATION: module/2:

Usage: :- module(Name,Exports).

DECLARATION: export/1:

Usage 1: :- export(Pred).

Usage 2: :- export(Exports).

DECLARATION: use_module/2:

Usage: :- use_module(Module,Imports).

DECLARATION: use_module/1:

Usage: :- use_module(Module).

DECLARATION: import/2:

Usage: :- import(Module,Imports).

DECLARATION: reexport/2:

Usage: :- reexport(Module,Preds).

DECLARATION: reexport/1:

Usage: :- reexport(Module).

DECLARATION: meta_predicate/1:

Usage: :- meta_predicate MetaSpecs.

REGTYPE: modulename/1:

Usage: modulename(M)

REGTYPE: metaspec/1:

A meta-predicate specification for a predicate is the functor of that predicate applied to atoms which represent the kind of module expansion that should be done with the arguments. Possible contents are represented as:

goal
This argument will be a term denoting a goal (either a simple or complex one) which will be called. For commpatibility reasons it can be named as : as well.
clause
This argument will be a term denoting a clause.
fact
This argument should be instantiated to a term denoting a fact (head-only clause).
spec
This argument should be instantiated to a predicate name, as Functor/Arity.
pred(N)
This argument should be instantiated to a predicate construct to be called by means of a call/N predicate call (see call/2). Thus, it should be an atom equal to the name of a predicate of arity N, or a structure with functor the name of a predicate of arity M (greater than N) and with M-N arguments.
?,+,-,_
These other values denote that this argument is not module expanded.

Usage: metaspec(M)


Go to the first, previous, next, last section, table of contents.