The functor of the head of Clause must be that of a predicate declared as dynamic, otherwise an error occurs. If no clause matches, it fails.
retract/1 satisfies the logical update semantics. When retract/1 is first called, it makes a virtual copy of the clauses that match and, on backtracking, unifies its argument with them and removes them from the database. Any modifications made to the procedure after retract/1 has started executing do not, in any way, affect its behaviour. A subsequent call, however, makes and uses a new, virtual, copy of the modified database.
Success:
[eclipse]: assert(city(munich)), assert(city(london)),
assert((p :- write(hi), write(there))).
yes.
[eclipse]: retract(city(X)).
X = munich More? (;)
yes.
[eclipse]: retract(city(X) :- Body).
X = london
Body = true
yes.
[eclipse]: retract(p :- Body).
Body = write(hi) , write(there)
yes.
Fail:
assert(fact),retract(fact),retract(fact).
Error:
retract(X). (Error 4).
retract("x"). (Error 5).
retract(listing). (Error 63).
retract(undef). (Error 70).