Dynamic Database

Static, dynamic and thread local predicates can be consulted. Dynamic and thread local predicates on the other hand can be also accessed and modified by the predicates here in. The predicate clause/2 matches clauses, the predicate retract/1 matches and removes clauses and the predicates asserta/1 and assertz/1 add a clause.

Examples:
?- assertz(p(a)).
Yes
?- p(X).
X = a
?- clause(p(X),Y).
X = a,
Y = true

The predicates clause/2, retract/1 and retractall/1 can only match clauses that are visible from the head predicate that is used in the search. The predicates asserta/1 and assertz/1 cannot redefine a predicate. Instead it must be marked multi-file. The clauses of a dynamic predicate are seen by all threads. A thread local predicate on the other hand has its own set of clauses for each thread.

Examples:
?- abolish(foo/1).
Yes
?- abolish(infix(=>)).
Yes

The predicate abolish/1 allows a predicate turning it non-existent again. The same predicate can be also used to remove operators by using indicators prefix/1, postfix/1 and infix/1. The predicate will attempt to remove own user clauses of the predicate, and only remove it if no system or foreign user clauses remain. If still some of the aforementioned clauses remain the predicate stays existent and non-empty.

The following dynamic database predicates are provided:

dynamic P, ...: [ISO 7.4.2.1]
The predicate sets the predicate P to dynamic.
thread_local P, …:
The predicate sets the predicate P to thread local.
group_local P, …:
The predicate sets the predicate P to group local.
clause(H, B): [ISO 8.8.1]
The predicate succeeds with the user clauses that match H :- B. The head predicate must be dynamic or thread local.
retract(C): [ISO 8.9.3]
The predicate succeeds and removes with the user clauses that match C. The head predicate must be dynamic or thread local.
retractall(H): [Corr.2 8.9.5]
The predicate succeeds and removes the user clauses that match the head H. The head predicate must be dynamic or thread local.
asserta(C): [ISO 8.9.1]
The predicate inserts the clause C at the top. The head predicate must be dynamic or thread local.
assertz(C): [ISO 8.9.2]
The predicate inserts the clause C at the bottom. The head predicate must be dynamic or thread local.
abolish(P): [ISO 8.9.4]
The predicate removes the predicate, evaluable function or syntax operator.

The following predicate properties for dynamic databases are provided:

dynamic:
The property indicates that the defined predicate is shared dynamic. The property cannot be set.
sys_dynamic(S):
The property indicates that the predicate has been marked dynamic in source context S. The property is multi valued and can be missing.
thread_local:
The property indicates that the clauses are local to the interpreter. The property cannot be set.
sys_thread_local(S):
The property indicates that the predicate has been marked thread local in source context S. The property is multi valued and can be missing.
group_local:
The property indicates that the clauses are local to the knowledge base. The property cannot be set.
sys_group_local(S):
The property indicates that the predicate has been marked group local in source context S. The property is multi valued and can be missing.

Comments