next up previous
Next: About this document Up: Global variables and DataBase Previous: assert

retract

likes(pooh,honey).
likes(Person, Anything) :-
 nice(Anything).
likes(fred,fish).

Q: retract((likes(fred,X) :- B)).
X = _567
B = nice(_0032)

On backtracking, this will delete the third clause, binding the variables as follows :

X = fish
Y = true

Combining retract and assert :

change( Variable, New_value) :- 
 retract( value( Variable, _)),
 assert( value( Variable, New_value)).

and

fast(anne).
slow(tom).
slow(pat).

Q: assert((faster(X,Y) :- fast(X), slow(Y))).
A: yes

Q: faster(A,B).
A: A = anne   B = tom

Q: retract(slow(X)).
A: X = tom; X = pat; no

Q: faster(anne,_)
A: no



Omer F Rana
Thu Feb 20 20:05:17 GMT 1997