As explained before, in the predicate based approach adapted by SWI-Prolog, each module has it's own predicate space. In SWI-Prolog, a module initially is completely empty. Predicates can be added to a module by loading a module file as demonstrated in the previous section, using assert or by importing them from another module.
Two mechanisms for importing predicates explicitly from another module exist. The use_module/[1,2] predicates load a module file and import (part of the) public predicates of the file. The import/1 predicate imports any predicate from any module.
It would be rather inconvenient to have to import each predicate referred to by the module, including the system predicates. For this reason each module is assigned a default module. All predicates in the default module are available without extra declarations. Their definition however can be overruled in the local module. This schedule is implemented by the exception handling mechanism of SWI-Prolog: if an undefined predicate exception is raised for a predicate in some module, the exception handler first tries to import the predicate from the module's default module. On success, normal execution is resumed.
SWI-Prolog contains two special modules. The first one is the module
system
. This module contains all built-in predicates
described in this manual. Module system
has no default
module assigned to it. The second special module is the module user
.
This module forms the initial working space of the user. Initially it is
empty. The default module of module user
is system
,
making all built-in predicate definitions available as defaults.
Built-in predicates thus can be overruled by defining them in module user
before they are used.
All other modules default to module user
. This implies
they can use all predicates imported into user
without
explicitly importing them.