Take the 2-minute tour ×

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:



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?


share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
Thanks, worked like a charm :) –  Davita Jan 21 '12 at 20:51

Your Answer


