Author(s): Daniel Cabeza and the CLIP Group.
Version: 1.7#195 (2002/4/12, 14:21:57 CEST)
Version of last change: 1.7#168 (2002/1/3, 17:45:2 CET)
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 [CH00a], 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 (that is, a predicate imported by an use_module/2
declaration is always preferred above a predicate imported by an use_module/1
declaration). 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).
Go to the first, previous, next, last section, table of contents.