next up previous
Next: Overruling Module Boundaries Up: Meta-Predicates in Modules Previous: Meta-Predicates in Modules

Definition and Context Module

Each predicate of the program is assigned a module, called it's definition module. The definition module of a predicate is always the module in which the predicate was originally defined. Each active goal in the Prolog system has a context module assigned to it.

The context module is used to find predicates from a Prolog term. By default, this module is the definition module of the predicate running the goal. For meta-predicates however, this is the context module of the goal that invoked them. We call this module_transparent in SWI-Prolog. In the `using maplist' example above, the predicate maplist/3 is declared module_transparent. This implies the context module remains extend, the context module of add_extension/3. This way maplist/3 can decide to call extend_atom in module extend rather than in it's own definition module.

All built-in predicates that refer to predicates via a Prolog term are declared module_transparent. Below is the code defining maplist.

:- module(maplist, maplist/3).

:- module_transparent maplist/3.

%	maplist(+Goal, +List1, ?List2)
%	True if Goal can succesfully be applied to all succesive pairs
%	of elements of List1 and List2.

maplist(_, [], []).
maplist(Goal, [Elem1|Tail1], [Elem2|Tail2]) :-
	apply(Goal, [Elem1, Elem2]), 
	maplist(Goal, Tail1, Tail2).

Passani Luca
Tue Nov 14 08:58:33 MET 1995