1
votes

I am very new to prolog. Trying to learn it as much as possible in as little time as possible. Any help is greatly appreciated. I am using MacOS Sierra by the way.

I am trying to input these lines:

nextto(_A,_B). 
nextto(_B,_C).

When I test using, prolog command window and execute this command:

?- nextto(A,C).

Isn't it supposed to return false?

Because, my compilation results in true, like this:

?- nextto(A,C).
true 
1
I need to code in such a way that nextto(A,C). is false.SAN
I don't think this is possible with nextto(A,C). Why not with nextto(a,c) instead???coder
Okay! Thank you so much!! Just wondering out of curiosity, so there is no way this can be achieved with uppercase letters?!SAN
if you consider them as characters e.g: 'A' sure but with capitals like A i don't know...coder
Alright! Thank you so much for quick replies!! I appreciate that!SAN

1 Answers

2
votes

In prolog _ is considered to be something like capital letter and it has its own special meaning which is to designate anonymous variable, so _A,_B are (anonymous) variables (whatever starts with capital in prolog is variable and not atom). Your clauses:

nextto(_A,_B). nextto(_B,_C).

actually means that predicate nexxto succeeds with two variables. So when you query neexto(A,C). it returns true. It would also return true if you query nextto(a,b). where now a,b are atoms and not variables, because it will examine if there is clause nextto(a,b). in your clauses. However as i said above your clause succeed with every unification of _A,_B. Also since your predicate nexxto always succeeds you would even get the same result with only writing the one clause:

nextto(_A,_B). 

instead of :

nextto(_A,_B). nextto(_B,_C).