4.14 Declaring predicates properties

This section describes directives which manipulate attributes of predicate definitions. The functors dynamic/1, multifile/1 and discontiguous/1 are operators of priority 1150 (see op/3), which implies the list of predicates they involve can just be a comma separated list:

:- dynamic
        foo/0,
        baz/2.

On SWI-Prolog all these directives are just predicates. This implies they can also be called by a program. Do not rely on this feature if you want to maintain portability to other Prolog implementations.

[ISO]dynamic :PredicateIndicator, \ldots
Informs the interpreter that the definition of the predicate(s) may change during execution (using assert/1 and/or retract/1). In the multi-threaded version, the clauses of dynamic predicates are shared between the threads. The directive thread_local/1 provides an alternative where each threads has its own clause-list for the predicate. Dynamic predicates can be turned into static ones using compile_predicates/1.
compile_predicates(:ListOfNameArity)
Compile a list of specified dynamic predicates (see dynamic/1 and assert/1) into normal static predicates. This call tells the Prolog environment the definition will not change anymore and further calls to assert/1 or retract/1 on the named predicates raise a permission error. This predicate is designed to deal with parts of the program that is generated at runtime but does not change during the remainder of the program execution.46The specification of this predicate is from Richard O'Keefe. The implementation is allowed to optimise the predicate. This is not yet implemented. In multi-threaded Prolog however, static code runs faster as it does not require synchronisation. This is particularly true on SMP hardware.
[ISO]multifile :PredicateIndicator, \ldots
Informs the system that the specified predicate(s) may be defined over more than one file. This stops consult/1 from redefining a predicate when a new definition is found.
[ISO]discontiguous :PredicateIndicator, \ldots
Informs the system that the clauses of the specified predicate(s) might not be together in the source file. See also style_check/1.
public :PredicateIndicator, \ldots
Instructs the cross-referencer that the predicate can be called. It has no semantics.47This declaration is compatible to SICStus. In YAP, public/1 instructs the compiler to keep the source. As the source is always available in SWI-Prolog, our current interpretation also enhanced the compatibility to YAP.