In Homework 4, we explored the notion of paths in family trees, where the path was the sequence of mom or dad relations between the initial family tree node and an ancestor with a desired trait. Here we will generalize the notion of paths to describe paths through binary trees, rather than family trees in particular.
We can view a path in this sense as specifying a route through given binary tree. We will define a function (follow-directions abt path) that returns the value of the node reached by following the input path in the input tree. For example, using the example binary trees defined above:
(follow-directions r123 '()) should be 123. (follow-directions m12 '(l r r)) should be #f. (follow-directions r123 '(l r)) should be 2.
Here is the data definition for a path:
a Path is either:
'()
(cons 'l path)
(cons 'r path)