I am studying on Ivan Bratko book: "Programming for Artificial Intelligence" for an universitary exame and using SWI Prolog and I have some doubts about an example show on this book regarding the assert and retract predicates.
It simply present the following code that declare some facts as dynamic:
:-dynamic fast(ann).
:-dynamic slow(tom).
:-dynamic slow(pat).
Then in the Prolog shell use the assert rule to define a new rule into the database:
[debug] 59 ?- assert((faster(X,Y) :- fast(X), slow(Y))).
true.
Ok, so the new rule seems to be added to my database.
Now I try to perform this query and it fail:
[debug] 64 ?- faster(X,Y).
false.
On the book say that the output should be this one:
A = ann
B = tom
and it sound good and rational because I have consult the previous program where say that specify who is fast and who is slow and later I have add the faster rule asserting it...
Why don't work? maybe it depends by the Prolog implementation (SWI-Prolog)?
dynamic
directive should merely indicate the predicate and its number of arguments, e.g.:- dynamic fast/1
and:-dynamic slow/1
. Asserting facts for these dynamic predicates is a separate (runtime) step. – hardmathassertz
on separate runs, it fails because there are none to retract. To permanently add to a knowledge base, you need an outputstream with append. – G_V