Using ! and fail, I’m trying negation by failure.
The method below however gives me the warning: Singleton variables: [X].
However, it seems to work so I’m wondering if there’s anything wrong with my method of doing it:
likes(vincent, big_kahuna_burger).
neg(X) :- X, !, fail.
neg(X).
So calling neg(likes(vincent, big_kahuna_burger)) will return false.
Your implementation of
negis correct. It’s just giving you a warning because in the second rule,Xis never used. If you writeyou will get no warning.