Are predicates (at the toplevel or even defined in files) by default dynamic?

Just running:

Welcome to SWI-Prolog (threaded, 64 bits, version 8.1.32-10-g1885b056f)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
 
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
 
?- assertz(tryit(alpha,beta)).
true.
 
?- tryit(A,B).
A = alpha,
B = beta.

I was not expecting this to work without a dynamic/1 statement.

Similarly, loading a file with

a(A,B) :- assertz(tryit(alpha,beta)),tryit(A,B).

No problem!

?- [test].
true.

?- a(X,Y).
X = alpha,
Y = beta.
1 Like

In the “Database” section in the manual, it says:

Dynamic predicates are predicates for which the list of clauses is modified at runtime using asserta/1, assertz/1, retract/1 or retractall/1.

The way that I understand this is that using any of these means that the predicate is, indeed, dynamic. In particular, for retractall/1, it says:

If Head refers to a predicate that is not defined, it is implicitly created as a dynamic predicate.

If you hover on footnote 80 in the docs for retractall/1 it also says,

The ISO standard only allows using dynamic/1 as a directive .

My understanding is that this implies that you can use dynamic/1 as a goal in a predicate body in SWI-Prolog, in contrast to what the ISO standard allows (and if you try it out you will see that you can, indeed, use dynamic/1 as a goal, not only as a directive).

I hope I am not misleading you on this.

2 Likes

Got it. Thank you for the responses.

I have added a comment to:

https://eu.swi-prolog.org/pldoc/doc_for?object=(dynamic)/1

Breadcrumbs for the next guy!

Prolog is like The House of Leaves: Bigger Inside!

2 Likes