Reputation: 5432
I am reading Learn Prolog Now, 1.1.2 Knowledge Base 2 where they write about chaining together uses of modus ponens.
The KB2.pl file:
listensToMusic(mia).
happy(yolanda).
playsAirGuitar(mia) :- listensToMusic(mia).
playsAirGuitar(yolanda) :- listensToMusic(yolanda).
listensToMusic(yolanda) :- happy(yolanda).
When the query:
playsAirGuitar(yolanda).
is submitted to gprolog, it is supposed to respond yes
, because it should be able to infer it from the fact that yolanda is happy.
But gprolog responds with no
. Why is that?
Upvotes: 3
Views: 237
Reputation: 5858
i think that the problem is that the clauses of the predicate listensToMusic/1 are separated.
the following code returns yes for me:
listensToMusic(mia).
listensToMusic(yolanda) :- happy(yolanda).
happy(yolanda).
playsAirGuitar(mia) :- listensToMusic(mia).
playsAirGuitar(yolanda) :- listensToMusic(yolanda).
you should get a warning like
warning: discontiguous predicate listensToMusic/1 - clause ignored
Upvotes: 2