Search code examples
prolog

PROLOG:How to exclude an option


I have this piece of code which suggests for a certain animal which other animals can coexist to it under those circumstances:

suggest(X) :- bigAnimal(X),bigAnimal(Y),coexist(X,Y),write(Y),nl,fail.

This loops until fail.My issue is that it prints out also the variable X

enter image description here

How can I exclude it from the output, thx in adcavance.


Solution

  • suggest(X) :-
        bigAnimal(X), bigAnimal(Y), X \== Y, coexist(X,Y), write(Y), nl, fail.