Section 2.2 - Hierarchical Data and the Closure Property
Section 2.2.1 - Representing Sequences
This is the iterative version:
We can use
append to create a recursive version:
But this will be more expensive because
append will iterate over each subset.
The three procedures are really simple actually, just renaming the list-operating procedures.
The order of list
coin-values does not affect the answer produced by
This is because the procedure is not based on any assumption regarding the order
of the elements.
Louis’ solution is essentially how we implemented
reverse for exercise 2.18.
Each iteration creates something like
(cons 9 (cons 4 (cons 1 nil))),
which is exactly how lists are implemented.
Unfortunately the second solution is no good either, because it is the inverse
of how lists are implemented, and results into something like
(cons (cons (cons nil 1) 4) 9). The order is correct, but this isn’t how
Scheme structures lists from