Prolog/Modifying the Database

< Prolog

This page is a stub.

From the SWI manual: [1]

Assert a fact or clause in the database. Term is asserted as the first fact or clause of the corresponding predicate. Equivalent to assert/1, but Term is asserted as first clause or fact of the predicate.

assertz(+Term, -Reference)
Equivalent to asserta/1, asserting the new clause as the last clause of the predicate.

When Term is an atom or a term it is unified with the first unifying fact or clause in the database. The fact or clause is removed from the database.

All facts or clauses in the database for which the head unifies with Head are removed. If Head refers to a predicate that is not defined, it is implicitly created as a dynamic predicate. See also dynamic/1.35


Let's start with an empty database:

?- human(john).
ERROR: toplevel: Undefined procedure: human/1 (DWIM could not correct goal)

?- assert(human(john)).

?- human(X).
X = john.