SICP exercise 2.18

From Drewiki

Jump to: navigation, search

Problem

Define a procedure reverse that takes a list as argument and returns a list of the same elements in reverse order:

 

Output:

(25 16 9 4 1)


Solution

There are several ways to implement this procedure, but the easiest way is to use append. Note that the result of appending a list foo to the empty list is just the list foo.

 

Test:

 

Output:

(25 16 9 4 1)
Personal tools