I'm trying to use the -> operator in GNU Prolog, but I'm having some trouble with variable scope. Here's an example:
example(A) :-
B = A,
(B == 2 -> write(B), write(' is 2'), nl);
(write(B), write(' is not 2'), nl).
In the Prolog console:
| ?- example(2).
2 is 2
true ?
yes
| ?- example(3).
_282 is not 2
yes
When I query example(2), B == 2 succeeds and Prolog knows what the value of B is and thus prints out 2 is 2.
On the other hand, when I query example(3), B == 2 fails and for some reason, Prolog does not know the value of B and therefore prints out some variable _282. I'm very confused as to why Prolog knows the value of B only when B == 2 succeeds. Am I not using the -> operator correctly? Any help would be appreciated.