The procedure must be declared to be dynamic using the dynamic/1 built-in. If the procedure is undefined an exception is raised. However, the default error handler for this exception simply declares the procedure dynamic and asserts the clause.
The asserted clause is NOT removed from the database on backtracking through the call to assertz/1.
assertz/1 satisfies the logical update semantics. Asserting a clause to a procedure will not, in any way, affect previous calls to it when backtracking.
No clause transformation is performed on Clause. Use expand_clause/2 to explicitly expand the clause before calling this predicate if clause expansion is rquired.
Success: ?- assertz(city(london)), assertz(city(munich)), assertz(city(paris)). yes. ?- listing. city(london). city(munich). city(paris). yes. ?- assertz((likes(X,Y) :- man(X), woman(Y))). yes. ?- listing. likes(_186, _187) :- man(_186), woman(_187). yes. Error: assertz(X). - gives error 4. assertz("the man"). - gives error 5. assertz(1). - gives error 5. assertz((my_static(X):-write(X))). - gives error 63. if my_static/1 is not dynamic. Logical semantics : If the following clauses are in the database : p :- assertz(p), fail. p :- fail. q :- fail. q :- assertz(q), fail. The queries p. and q. will both fail.