Every clause in a Prolog file has a source module implicitly associated with it. If the file is a module-file, 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, 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:
a/1is declared dynamic in the module
b/1is defined in module
a(the module of the file).
c/1is defined in module
d/1is defined in module
r/1are called in module
a(and must therefore be defined in module
e/1is defined in module
t/1are called in module
f/1is defined in module
v/1are called in module
Module prefixing is especially useful when the module prefix is
are several predicates that have to be defined in module
that you may want to define (or extend) in a program that is otherwise
entirely defined in some other module or modules;
Note that if clauses for one of these predicates are to be spread across multiple files, it will be necessary to declare that predicate to be multifile by putting a multifile declaration in each of the files.