SICP Exercise 2.39 reverse as fold

Exercise 2.39.   Complete the following definitions of reverse (exercise 2.18) in terms of fold-right and fold-leftfrom exercise 2.38:

(define (reverse sequence)
  (fold-right (lambda (x y) <??>) nil sequence))
(define (reverse sequence)
  (fold-left (lambda (x y) <??>) nil sequence))


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