I'm using SWI for Windows and I'm trying out an exercise in Learn Prolog Now!
travel(Start,Dest,X) :-
(byCar(Start,Dest); byTrain(Start,Dest); byPlane(Start,Dest)),
X = go(Start,Dest).
In this code if the you can reach Dest from Start, Prolog says:
true.
X = go(Start,Dest).
and just says false otherwise.
However in this code when I removed the parenthesis it only says true if valid and false if invalid. The answer is correct but why doesn't it output X?
travel(Start,Dest,X) :-
byCar(Start,Dest); byTrain(Start,Dest); byPlane(Start,Dest),
X = go(Start,Dest).
Is it because of operator precedence in which AND gets evaluated first? Even if thats the case shouldn't X still be equal to go(Start,Dest)?
The way Prolog assigns values to variables confuses me.