Next: , Previous: , Up: ref-mod   [Contents][Index]


4.11.10 Module Prefixes on Clauses

Every clause in a Prolog file has a source module implicitly associated with it. If the file is a module file, then the module named in the module declaration at the top of the file is the source module for all the clauses. If the file is not a module file, then the relevant module is the source module for the command that caused this file to be loaded.

The source module of a predicate decides in which module it is defined (the module of the head), and in which module the goals in the body are going to be called (the module of the body). It is possible to override the implicit source module, both for head and body, of clauses and directives, by using prefixes. For example, consider the module file:

:- module(a, []).

:- dynamic m:a/1.               
b(1).                           
m:c([]).                        
m:d([H|T]) :- q(H), r(T).       
m:(e(X) :- s(X), t(X)).
f(X) :- m:(u(X), v(X)).

In the previous example, the following modules apply:

  1. a/1 is declared dynamic in the module m.
  2. b/1 is defined in module a (the module of the file).
  3. c/1 is defined in module m.
  4. d/1 is defined in module m, but q/1 and r/1 are called in module a (and must therefore be defined in module a).
  5. e/1 is defined in module m, and s/1 and t/1 are called in module m.
  6. f/1 is defined in module a, but u/1 and v/1 are called in module m.

Module prefixing is especially useful when the module prefix is user. There are several predicates that have to be defined in module user but that you may want to define (or extend) in a program that is otherwise entirely defined in some other module or modules; see mpg-top-hok.

Note that if clauses for one of these predicates are to be spread across multiple files, then it will be necessary to declare that predicate to be multifile by putting a multifile declaration in each of the files.



Send feedback on this subject.