Different query results in prolog

帅比萌擦擦* 提交于 2021-01-29 04:30:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!