0
votes

I'm learning Prolog from "Learn prolog now" book. I'm quite newbie in prolog and sorry for that stupid question :).

I have such knowledge base:

  loves(vincent,mia). 
  loves(marsellus,mia). 
  loves(pumpkin,honey_bunny). 
  loves(honey_bunny,pumpkin). 

  jealous(X,Y):-  loves(X,Z),  loves(Y,Z).

we see that vincent and marsellus both loves mia. We also have jealous complex terms to identify jealous persons. So, if I query KB with jealous(vincent, X). logically, I should get all persons who is in love with mia, except vincent (marsellus in this case), but the query returns both vincent and marsellus. I understand that the query works correctly technically, but my question is, how can I query jealous peoples in the way to ommit the first parameter (vincent in this case) from query result?

Thanks.

1

1 Answers

2
votes

Write the complex query like this:

jealous(X,Y):-  loves(X,Z),  loves(Y,Z), X \== Y.

Which means, X and Y cannot be the same.