This section describes directives which manipulate attributes of
predicate definitions. The functors dynamic/1, multifile/1,
are operators of priority 1150 (see op/3),
which implies that the list of predicates they involve can just be a
In 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.
Notably with the introduction of tabling (see section
7) it is common that a set of predicates require multiple options to
be set. SWI-Prolog offers two mechanisms to cope with this. The
can be used to make a list of predicates dynamic and set additional
options. In addition and for compatibility with XSB,91Note
as is in XSB a high-priority operator and in SWI a
low-priority and therefore both the sets of predicate indicators as
multiple options require parenthesis. all the predicates
below accept a term
as((:PredicateIndicator, ... ), (+Options)),
where Options is a comma-list of one of more of the
- Include a dynamic predicate into the incremental tabling dependency
graph. See section
- Opposite of
incremental. For XSB compatibility.92In
opaque is distinct from the default in the sense that
dynamic switching between
- Used together with
incremental to reduce the dependency
graph. See section
- Do not save this predicate. See volatile/1.
- Predicate may have clauses in multiple clauses. See multifile/1.
- Predicate clauses may not be contiguous in the file. See
- Dynamic predicate is shared between all threads. This is currently the
- Dynamic predicate has distinct set of clauses in each thread. See
Below are some examples, where the last two are semantically
:- dynamic person/2 as incremental.
:- dynamic (person/2,organization/2) as (incremental, abstract(0)).
:- dynamic([ person/2,
- [ISO]dynamic :PredicateIndicator,
- Informs the interpreter that the definition of the predicate(s) may
change during execution (using assert/1
In the multithreaded version, the clauses of dynamic predicates are
shared between the threads. The directive thread_local/1
provides an alternative where each thread has its own clause list for
the predicate. Dynamic predicates can be turned into static ones using
- As dynamic/1,
but allows for setting additional properties. This predicate allows for
setting multiple properties on multiple predicates in a single call.
SWI-Prolog also offers the XSB compatible
:- dynamic (p/1)
as (incremental,abstract(0)). syntax. See the introduction of section
4.15. Defined Options are:
- Make the dynamic predicate signal depending tables. See
- This option must be used together with
only supported value is
0. With this option a call to the
incremental dynamic predicate is recorded as the most generic term for
the predicate rather than the specific variant.
- Local is one of
shared (default) or
See also thread_local/1.
- Set the corresponding property. See multifile/1, discontiguous/1
- Compile a list of specified dynamic predicates (see dynamic/1
into normal static predicates. This call tells the Prolog environment
the definition will not change anymore and further calls to assert/1
on the named predicates raise a permission error. This predicate is
designed to deal with parts of the program that are generated at runtime
but do not change during the remainder of the program execution.93The
specification of this predicate is from Richard O'Keefe. The
implementation is allowed to optimise the predicate. This is not yet
implemented. In multithreaded Prolog, however, static code runs faster
as it does not require synchronisation. This is particularly true on SMP
- [ISO]multifile :PredicateIndicator,
- 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,
- 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,
- Instructs the cross-referencer that the predicate can be called. It has
no semantics.94This declaration is
compatible with 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 enhances the
compatibility with YAP. The public declaration can be
queried using predicate_property/2.
not export the predicate (see module/1
The public directive is used for (1) direct calls into the module from,
e.g., foreign code, (2) direct calls into the module from other modules,
or (3) flag a predicate as being called if the call is generated by
meta-calling constructs that are not analysed by the cross-referencer.
- non_terminal :PredicateIndicator,
- Sets the
non_terminal property on the predicate. This
indicates that the predicate implements a grammar rule. See
non_terminal property is set for predicates exported as Name//Arity
as well as predicates that have at least one clause written using the