# Recursive travel

**URL:** <https://swi-prolog.discourse.group/t/recursive-travel/1281>\
**Category:** Help!\
**Tags:** discussion\
**Created:** [September 18, 2019, 10:51am UTC](https://swi-prolog.discourse.group/t/recursive-travel/1281 "2019-09-18T10:51:53Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [September 19, 2019, 10:58am UTC](https://swi-prolog.discourse.group/t/recursive-travel/1281/20 "2019-09-19T10:58:37Z")

</div>

> [@DaJa](#):
>
> When/how is transportation mode added to Path?
> 
> ```prolog
> travel_01_helper(X,Y,Path0,[(Mode,Y)|Path0]) :-
> (
> (byCar(X,Y),Mode = car)
> ;
> (byTrain(X,Y),Mode = train)
> ;
> (byPlane(X,Y),Mode = plane)
> ),
> \+ member((_,Y),Path0).
> 
> ```

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](https://www.swi-prolog.org/pldoc/man?predicate=%3D/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.

```prolog
?- Mode = car.
Mode = car.

?- =(Mode,car).
Mode = car.

```

* * *

If you want to look at other somewhat simple Prolog examples see [RosettaCode](http://rosettacode.org/wiki/Rosetta_Code) - [Prolog](http://rosettacode.org/wiki/Category:Prolog)

For other useful links see: [Useful Prolog references](https://swi-prolog.discourse.group/t/useful-prolog-references/1089)

---

_[View the full topic](https://swi-prolog.discourse.group/t/recursive-travel/1281)._
