with this knowledge base using https://swish.swi-prolog.org
:- dynamic happy/1.
go:-
assert(happy(mia)),
write(happy(mia)).
if I run go. I get
happy(mia)
true
If I just have
:- dynamic happy/1.
assert(happy(mia)).
and run happy(mia), I get false.
What fundamental concept am I missing please?
When you write:
you are (re)defining the predicate
assert/1, not calling it as in your definition of thego/0predicate. Thus,happy(mia)is never added to the database. The query fails as the predicatehappy/1is know by the system (thanks to thedynamic/1directive) but have no clauses.Most Prolog systems prevent the redefinition of standard built-in predicates. But
assert/1is a legacy/deprecated predicate. That explains why SWI-Prolog doesn't complain about the redefinition. Always use the standardassertz/1predicate instead ofassert/1.