As explained before, in the predicate based approach adapted by SWI-Prolog, each module has its 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.
importoption of load_files/2. The first example below loads member/2 from the lists library and append/2 under the name
list_concat, which how this predicate is named in YAP. The second example loads a all exports from library option, except for meta_options/3. These renaming facilities are generally used to deal with portability issues with as few as possible changes to the actual code. See also section C and section 5.5.
:- use_module(library(lists), [ member/2, append/2 as list_concat ]). :- use_module(library(option), except([meta_options/3])).
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 one of the module's import modules. 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
This module forms the initial working space of the user. Initially it is
empty. The import module of module
making all built-in predicate definitions available as defaults.
Built-in predicates thus can be overruled by defining them in module
before they are used.
All other modules import from the module
implies they can use all predicates imported into
without explicitly importing them.