The predicates defined in this section allow modification of dynamic predicates. Dynamic clauses can be added (asserted) or removed from the program (retracted).
SICStus Prolog implements the “logical” view in updating dynamic predicates. This means that the definition of a dynamic predicate that is visible to a call is effectively frozen when the call is made. A predicate always contains, as far as a call to it is concerned, exactly the clauses it contained when the call was made.
A useful way to think of this is to consider that a call to a dynamic predicate makes a virtual copy of its clauses and then runs the copy rather than the original clauses. Any changes to the predicate made by the call are immediately reflected in the Prolog database, but not in the copy of the predicate being run. Thus, changes to a running predicate will not be visible on backtracking. A subsequent call, however, makes and runs a copy of the modified Prolog database. Any changes to the predicate that were made by an earlier call will now be visible to the new call.
For the predicates of this section, the argument Head
must be instantiated to an atom or a compound term,
with an optional module prefix. The argument Clause
must be instantiated either to a term Head
Body or, if the body part is empty, to Head, with an
optional module prefix. An empty body part is represented
Note that a term Head
:- Body must be enclosed
in parentheses when it occurs as an argument of a compound
term, as `:-' is a standard infix operator with
precedence greater than 1000 (see Operators), e.g.:
| ?- assert((Head :- Body)).
Like recorded terms (see Database), the clauses of dynamic predicates have a unique implementation-defined identifier. Some of the predicates below have an additional argument, which is this identifier. This identifier makes it possible to access clauses directly instead of requiring a normal database (hash-table) lookup.
assert/2, except that the new clause becomes the first clause for the predicate concerned.
assert/2, except that the new clause becomes the last clause for the predicate concerned.
)exists in the database, and its database reference is Ref. The predicate concerned must currently be dynamic. At the time of call, either Ref must be instantiated, or Head must be instantiated to an atom or a compound term. Thus
clause/3can have two different modes of use.
retract/1may be used in a nondeterminate fashion, i.e. it will successively retract clauses matching the argument through backtracking.
Please note: all predicates mentioned above first look for a predicate that is visible in the module in which the call textually appears. If no predicate is found, a new dynamic predicate (with no clauses) is created automatically. It is recommended to declare as dynamic predicates for which clauses will be asserted.
/Arity. Name may be prefixed by a module name (see Module Spec). In
isoexecution mode only dynamic predicates can be abolished. In
sicstusexecution mode only built-in predicates cannot be abolished, the user-defined ones always can be, even when static.