Recursion

Next: Representing information spatially (AI)
Previous: More connection predicates
Back: to main list of student notes

## Recursion

This exercise is more difficult, but worth trying. Can you write a predicate

`    on_route_to( Cave1, Cave2 ) :-`
which is true if Cave1 is connected to Cave2 by a path of any length. (If you look at your map, you will see that not all the caves are connected: i and j are joined to each other, but to no other caves. k is joined to no others at all.)

When trying this, some people say ``there are only eleven caves, so I only need a finite number of facts: I'll just enumerate all possible connections''. That is not what I want. I want a general rule that will work no matter what the map.

This is harder, and I don't expect everyone will manage it; but if you were able to do the `is_ancestor_of` example in Lesson 2, you should be able to cope with this, and then you'll be well on the way to understanding recursion. There was another example of recursion in the `flows_to` predicate of Supplement 1. In the Traveller trading game of Supplement 4, you will see a use for such a predicate.

Next: Representing information spatially (AI)