问题
I have a question in prolog. Here is the Knowledge Base.
loves(vincent,mia).
loves(marcellus,mia).
loves(pumpkin,honey_bunny).
loves(honey_bunny,pumpkin).
jealous(X,Y) :-
loves(X,Z),
loves(Y,Z).
This is from "Learn Prolog Now" book. Now if I make a query ?- jealous(marcellus,W).
it returns that W = vincent
but if I give the query ?- jealous(vincent,W).
the return result is W=vincent
So this means that vincent is jealous of himself but marcellus is not jealous of himself. Why is the answer different ?
I am using swipl in Ubuntu Linux , which is in VirtualBox on winxp. I am beginner in Prolog.
Thanks
回答1:
After the answer W = vincent
at the query ?- jealous(marcellus,W).
type ;
instead of Enter
and you will get W = marcellus.
You must add the fact that X \= Y
in jealous/2
.
来源:https://stackoverflow.com/questions/12757406/different-query-results-in-prolog