|
|
The reduction functions |
The function reduce-right is a straightforward recursive function The function reduce-left is a straightforward iterative function |
Notice the fit between the composition of the list and the recursive pattern of the
right reduction. |
There is a misfit between left reduction and the recursive composition of the list with heads and tails.
However, an iterative process where we successively combine e1 and e2 (giving r1), r1 and e3 etc., is straightforward.
As we have seen several times, this can be done by a tail recursive function, here reduce-help-left. |
| Examples of reductions.
The - left reduction of the list corresponds to calculating the expression
(- (- (- (- 1 2) 3) 4) 5).
The - right reduction of the list corresponds to calculating the expression
(- 1 (- 2 (- 3 (- 4 5)))).
|
|