Exercise 2.20 deals with functions that take arbitrary number of arguments. This is extremely useful in the context of scheme because it allows you to use less brackets :).
Exercise 2.20
1 2 3 4 5 6 7 8 |
|
I used reverse
followed by the same-parity-iter
because I did not want to use the inefficient
append
function.
1 2 |
|
The sections also introduces us to the map
higher order function.
1 2 3 4 5 |
|
But why map? Quoting SICP
The different between the two definitions is not that the computer is performing a different process (it isn’t) but that we think about the process differently. In effect, `map` helps establish an abstraction barrier that isolates the implementation of procedures that transforms lists from the details of how the elements of the list are extracted and combined.
This is the most succint way to put across the need for abstractions. Abstractions are invented to help us think differently and care about different things.
Exercise 2.21
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Exercise 2.22
1 2 3 4 5 6 7 8 9 10 11 |
|
Interchanging the arguments of cons does not work as it will generate a list of lists instead of generating a single list.
Exercise 2.23
1 2 3 4 5 6 7 8 9 |
|