A declaration
:- multifile PredSpec, ..., PredSpec. ISO
where each PredSpec is a predicate spec, causes the specified predicates to become multifile. This means that if more clauses are subsequently loaded from other files for the same predicate, then the new clauses will not replace the old ones, but will be added at the end instead. As of release 3, multifile declarations are required in all files from where clauses to a multifile predicate are loaded.
An example when multifile declarations are particularly
useful is in defining hook predicates. A hook predicate is
a user-defined predicate that somehow alters or customizes the
behavior of SICStus Prolog. A number of such hook predicates are
described in this manual. Often, an application needs to combine the
functionality of several software modules, some of which define
clauses for such hook predicates. By simply declaring every
hook predicates as multifile, the functionality of the
clauses for the hook predicates is automatically combined.
If this is not done, the last software module to define
clauses for a particular hook predicate will effectively
supersede any clauses defined for the same hook predicate in
a previous module. By default, hook predicates must be
defined in the user
module, and only their first solution
is relevant.
If a file containing clauses for a multifile predicate is reloaded, the old clauses from the same file are removed. The new clauses are added at the end.
If a multifile predicate is loaded from a file with no multifile declaration for it, the predicate is redefined as if it were an ordinary predicate (i.e. the user is asked for confirmation).
Clauses of multifile predicates are (currently) always loaded in interpreted form, even if they were processed by the compiler. If performance is an issue, define the multifile predicates as unit clauses or as clauses with a single goal that just calls an auxiliary compiled predicate to perform any time-critical computation.
If a multifile predicate is declared dynamic in one file, it must also be done so in the other files from where it is loaded. Hook predicates should always be declared as multifile and dynamic, as this is the convention followed in the library modules.
Multifile declarations must precede any other declarations for the same predicate(s)!