See also:
Database Section which has more on this.
Predicates that are unknown are implicitly defined as dynamic when they appear first-time in: asserta/1, asserta/2, assertz/1, assertz/2, retract/2, retractall/1
Examples:
Use predicate like a dynamic predicate, but the predicate was previously used non-dynamically: NO
?- [user]. |: tryit_0(a,b). |: % user://1 compiled 0.02 sec, 1 clauses true. ?- assertz(tryit_0(c,d)). ERROR: No permission to modify static procedure `tryit_0/2'
Declared as dynamic before use: YES
?- [user]. |: :- dynamic(tryit_1/2). |: tryit_1(a,b). |: % user://1 compiled 0.02 sec, 1 clauses true. ?- assertz(tryit_1(c,d)). true. ?- bagof([X,Y],tryit_1(X,Y),Bag). Bag = [[a, b], [c, d]].
In SWI Prolog, dynamic/1 also appears as a predicate
?- dynamic(tryit_2/2). true. ?- assertz(tryit_2(a,b)). true. ?- bagof([X,Y],tryit_2(X,Y),Bag). Bag = [[a, b]].
Use a previously unknown predicate dynamically: Implicitly dynamic
?- assertz(tryit_3(a,b)). true. ?- predicate_property(tryit_3(_,_),dynamic). true.
Edge case: Testing for dynamic property before use
?- predicate_property(tryit_5(_,_),dynamic). % Should properly throw, really false. ?- assertz(tryit_5(a,b)). true. ?- predicate_property(tryit_5(_,_),dynamic). true.