Did you know ... | Search Documentation: |
Predicate assert/1 |
resource_error(program_space)
exception. The example below
adds two facts and a rule. Note the double parentheses around the rule.
?- assertz(parent('Bob', 'Jane')). ?- assertz(female('Jane')). ?- assertz((mother(Child, Mother) :- parent(Child, Mother), female(Mother))).
The retractall/1 predicate removes all clauses whose head matches the argument from a dynamic predicate. The abolish/1 predicate takes a predicate indicator to remove all clauses and all properties.
:- dynamic p/1.
?- assertz(p(a)). ?- assertz(p(b)). ?- retractall(p(b)). ?- p(a). true. ?- p(b). false. ?- retractall(p(_)). ?- p(X). false.
?- assertz(p(a)). ?- assertz(p(b)). ?- abolish(p/1). ?- p(X). ERROR: Unknown procedure: p/1 (DWIM could not correct goal)
A dynamic predicate is introduced using dynamic/1, after which clauses may be added using assertz/1. Persistent dynamic predicates are realized using library(persistency).
:- dynamic p/1.
?- assertz(p(a)). ?- p(X). X = a. ?- retractall(p(_)). ?- p(X). false.