Well i’m just wondering why does it work, where prolog loose variable.
?- \+ \+ member(X,[a]),X=b.
X=b.
Where X=a. automagicly vanished.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
\+/1is not “not” in the logical sense, but is implemented through “negation as failure”. That means,\+ Goalsucceeds iffGoalfails.Think of
\+/1as being implemented as:As you can see, in both cases can no variable in
Goalbecome bound. In the “if” branch, any binding will be undone by backtracking, and in the “else” branch, no variable will have been become bound anyway.In your example,
member(X,[a]succeeds by bindingXtoa. This will have\+ member(X,[a])fail, and so\+\+ member(X,[a])succeeds because of this failure. Due to the intermediate failure,Xwill not be bound toa.