SICP exercise 2.33

From Drewiki

Jump to: navigation, search

Problem

Fill in the missing expressions to complete the following definitions of some basic list-manipulation operations as accumulations:

 

Solution

Here's the definition of accumulate as given in the text:

 

Here's an implementation of map which uses accumulate:

 

Test:

 

Output:

(4 9 25 49 64)


An implementation of append:

 

Test:

 

Output:

(1 2 3 4 5 6 7 8)


And finally, length:

 

Test:

 

Output:

4
 

Output:

0
 

Output:

6
Personal tools