SICP Exercise 2.27 deep-reverse

Exercise 2.27.  Modify your reverse procedure of exercise 2.18 to produce a deep-reverse procedure that takes a list as argument and returns as its value the list with its elements reversed and with all sublists deep-reversed as well. For example,



(define x (list (list 1 2) (list 3 4)))

x
((1 2) (3 4))

(reverse x)
((3 4) (1 2))

(deep-reverse x)
((4 3) (2 1))


SOLUTION

The code and tests are here.

Comments

Popular posts from this blog

SICP Exercise 4.9 do for while until

SICP Exercise 3.56 merge streams

SICP Exercise 1.22 search-for-primes