Project "Contraintes" Prolog Web Pages: Modules

Prolog Modules: The state of Part 2.

The creation of an ISO standard for Prolog modules has been complicated by the existence of metapredicates and other context sensitive predicates which must have access to the identity of the module in which they are called for their implementation.

Two competing mechanisms were proposed,

In January 1999 it became clear that no agreement would be reached that standardized either of these two methods as the required one. An unchangeable Prolog flag colon_sets_calling_context was therefor agreed upon. If the flag has the value true then the first mechanism is to be used for determining the calling context. If the value has the value false some other mechanism for providing context information must be used, perhaps the second, but the standard will not require this.

The basics of the Proposal

Syntax of Module Text

Prolog text which uses modules is consists of a sequence of

Module Interface

A module interface is a sequence of directives, the first of which is
:- module(module_name). and the last of which is
:- end_module(module_name). Note that the name tags must match.

Only module interface directives may appear between these two directives. These are

Module Interface directives

op/3, char_conversion/2 and set_prolog_flag/2 as module interface directives

When used in a module interface these directives specify that their effects are in force from the start of the first body of the module. Unlike the use of these directives in Prolog text in this case their effect is only on the associated bodies of the module.

Exporting Procedures

A module may export a predicate that it defines. This fact is advertised by using the export/1 directive.

A module may not export a procedure that it has imported (or re-exported). Rather a special module interface directive is provided for this purpose.

Re-exporting Procedures

Rather than allowing a module to export procedures that it has imported the required effect is obtained by the two directives
which allows a module m to 'import' the exports (and re-exports) of all the modules designated by the directive's argument (which can be a single atom, an atom list or a comma separate list of atoms) to be visible in the module and makes it possible for other modules to import (re-export) these same predicates by importing the module m.
which is a selective version of reexport/1 allowing only the re-export of certain predicates from a module.


Meta-predicates are predicates which must know the context in which they are invoked in order to act properly. Typically (but not necessarily) these are predicates one or more of whose arguments may be unified to a goal that is called by the execution of the predicate. call/1 and setof/3 are two examples from the builtin predicates. Since this may affect both compilation and the way in which a programmer may use such predicates the interface to a module is required to declare the meta-predicates of the module.

Module Body

Two new directives are required that can appear in a module body.
allows a module to import the exports (ans re-exports) of all the modules designated by the directive's argument (which can be a single atom, an atom list or a comma separate list of atoms.)
A selective version of the above in which only certain predicates from a given module are imported.

New Required Predicates


current_module(Module) is true if and only if Module unifies with the name of an existing module.

Template: current_module(?atom)


predicate_property(Prototype, Property) is true in the calling context of a module M if and only if the procedure associated with the argument Prototype has predicate property Property.

Template: predicate_property(+prototype, ?predicate_property)

Author: J.P.E. Hodgson
Saint Joseph's University
Philadelphia PA 19131

Last Changed: 1999/06/24