retract/2

Deletes the first matching clause at a known position; if the position is a variable, it is instantiated to the position of the retracted clause

retract(Clause,Position) -(i,i),(i,o)

+Clause <clause>

?Position <integer> or <variable>

Compatibility: LPA Win-Prolog, most other Prologs.

Remarks: This deletes the first matching Clause from a predicate, returning its Position, or deletes a specific Clause at a given Position. The given Clause can be partially or fully instantiated, although as a minimum its head must include the predicate name, and any arguments must be fully enumerated. Where Position is an unbound variable, attempts are made to unify Clause with successive program clauses, and if a match is found, the clause in question is deleted and its clause number is bound to Position. If Position is given, only the indicated Clause is matched and, if successful, deleted. In either case, on backtracking, attempts are made to find and delete further matching clauses. When no (more) matching clauses are found, the call fails; if the target predicate did not previously exist, the call fails.