The details can be seen by using trace/0 with protocol/1 as noted in the earlier post. Here I will just explain the details without showing the code or the trace.
The predicate travel_01_helper/4 is entered on the first line with the first three arguments bound, so [(Mode,Y)|Path0]
is not fully bound but, Y
and Path0
are bound because they were bound when the predicate was entered.
Next there are thee possibilities for the next statement because of the use of ;
. When one of the three predicates, e.g. byCar(X,Y)
succeeds/returns true, then the next predicate is called, e.g. Mode = car
and via unification =/2, the unbound variable Mode
is bound to the value.
In the example Mode = car
, =/2
is used as an infix operator as opposed to a prefix operator.
?- Mode = car.
Mode = car.
?- =(Mode,car).
Mode = car.
If you want to look at other somewhat simple Prolog examples see RosettaCode - Prolog
For other useful links see: Useful Prolog references