Track changes to a predicate. This notably allows tracking modifications
to dynamic predicates. The channel also allows tracking changes to
monotonic tables (section
7.8). Both monotonic and incremental tabling use this to track
changes to incremental
and monotonic
dynamic
predicates. Below is an example illustrating events from changing a
dynamic predicate.
:- dynamic p/1.
:- prolog_listen(p/1, updated(p/1)).
updated(Pred, Action, Context) :-
format('Updated ~p: ~p ~p~n', [Pred, Action, Context]).
?- assert(p(a)).
Updated p/1: assertz <clause>(0x55db261709d0)
?- retractall(p(_)).
Updated p/1: retractall start(user:p(_12294))
Updated p/1: retract <clause>(0x55db261719c0)
Updated p/1: retractall end(user:p(_12294))
- asserta
- assertz
- A new clauses has been added as first (last) for the given predicate. Context
is a clause reference. The hook is called after the clause has been
added. If the hook fails the clause is removed.
- retract
- A clause was retracted from the given predicate using either
retract/1, erase/1
or retractall/1. Context
is a clause reference. The hook is called before the clause is removed.
If the hook fails, the clause is not removed.
- retractall
- The begining and end of retractall/1
is indicated with the Action
retractall
. The
context argument is start(Head)
or end(Head)
.
- rollback(Action)
- Issued when rolling back (discarding) a transaction. Action
is the local action being reverted and is one of
asserta
,
assertz
or retract
. Context is the involved
clause. See transaction/1
and snapshot/1.
- new_answer
- A new answer was added to a tabled predicate. The context is the answer
term. Currently implemented for monotonic tabling only. Future
versions may also implement this for normal tabling. See section
7.8.2.