projog

3.100. retractall(X) - remove clauses from the knowledge base.

All clauses that X matches are removed from the knowledge base. X must be suitably instantiated that the predicate of the clause can be determined.

Examples

?- assertz(x(1,a)).

yes

?- assertz(x(2,b)).

yes

?- assertz(x(3,a)).

yes

?- assertz(y(1,a)).

yes

?- x(X,Y).
X = 1
Y = a

yes;
X = 2
Y = b

yes;
X = 3
Y = a

yes

?- y(X,Y).
X = 1
Y = a

yes

?- retractall(x(_,a)).

yes

?- x(X,Y).
X = 2
Y = b

yes

?- y(X,Y).
X = 1
Y = a

yes

?- retractall(x(_,_)).

yes

?- x(X,Y).

no

Succeeds even if there are no facts to remove

?- retractall(x(_,_)).

yes

?- retractall(xyz(_)).

yes

Argument must be suitably instantiated that the predicate of the clause can be determined.

?- retractall(X).

Expected an atom or a predicate but got a VARIABLE with value: X

?- retractall(true).

Cannot inspect clauses of built-in predicate: true/0

?- retractall(is(1,2)).

Cannot inspect clauses of built-in predicate: is/2

non_dynamic_predicate(1,2,3).

?- retractall(non_dynamic_predicate(1,2,3)).

Cannot retract clause from user defined predicate as it is not dynamic: non_dynamic_predicate/3

?- retractall(non_dynamic_predicate(_,_,_)).

Cannot retract clause from user defined predicate as it is not dynamic: non_dynamic_predicate/3

?- retractall(non_dynamic_predicate(4,5,6)).

yes