multifile/1 declaration

Synopsis

:- multifile +PredSpecs

Allows the clauses for the specified predicates to be in more than one file.

Arguments


PredSpecs pred_spec_forest [MOD]
A single predicate specification of the form Name/Arity, or a sequence of predicate specifications separated by commas. Name must be an atom and Arity an integer in the range 0..255.

Description

A built-in prefix operator, so that declarations can be written as e.g.

      :- multifile a/1, b/3.
     

By default, all clauses for a predicate are expected to come from just one file. This assists with reloading and debugging of code. Declaring a predicate multifile means that its clauses can be spread across several different files. This is independent of whether or not the predicate is declared dynamic.

Should precede all the clauses for the specified predicates in the file.

There should be a multifile declaration for a predicate P in every file that contains clauses for P. This restriction is not currently enforced in the Development System: for compatibility with earlier releases it suffices to have a multifile declaration in the first file loaded that contains clauses for P. However, a warning is noted if the multifile declaration is omitted in subsequent files. The multifile declarations must be included in every file when qpc is being used to compile files separately.

If a multifile predicate is dynamic, there should be a dynamic declaration in every file containing clauses for the predicate. Again, this is not enforced in the Development System, for backwards compatibility, but warnings are printed if the dynamic declarations are omitted. The dynamic declarations may not be omitted when qpc is being used to compile files separately.

When a file containing clauses for a multifile predicate (P) is reloaded, the clauses for P that previously came from that file are removed. Then the new clauses for P (which may be the same as the old ones) are added to the end of the definition of the multifile predicate. An exception to this is when the file concerned is the pseudo-file user, meaning that clauses are being entered from the terminal; in this case the clauses are always added to the end of the predicate without removing any previously defined clauses.

If a multifile declaration is found for a predicate that has already been defined in another file (without a multifile declaration), then this is considered to be a redefinition of that predicate. Normally this will result in a multiple-definition style-check warning (see style_check/1).

The predicate source_file/2 can be used to find all the files containing clauses for a multifile predicate.

multifile predicates can be extended at run-time using multifile_assertz/1.

multifile/1 cannot be called as a built-in predicate. It can only be used as a declaration to the compiler in a Prolog source file.

Exceptions


instantiation_error
PredSpecs not ground.
type_error
Either name or arity in PredSpec has the wrong type
domain_error
Arity not in the range 0..255.
context_error
If the declaration contradicts previous declaration or clauses for the same predicate in the file.

See Also

multifile_assertz/1, source_file/[1,2], compile/1, load_files/[1,2], dynamic/1.