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 one, the colon (':') which is
already to be used to determine the module in which search for a
given predicate is to be conducted, is overloaded to provide the context
- in the other a new operator '@' is provided to set the context
in which a predicate is invoked.
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
A module interface is a sequence of directives, the first
of which is
- Module Interfaces
- Module Bodies
- Clauses and directives that are not part of any module interface or body.
These belong to the required default module system
and the last of which is
Note that the name tags must match.
Only module interface directives may appear between these two
directives. These are
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.
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.
Rather than allowing a module to export procedures that it has imported the required effect is obtained by the two directives
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.
Two new directives are required that can appear in a module body.
- 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.
current_module(Module) is true if and only if Module unifies with
the name of an existing module.
- 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.
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