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 2.56 differentiation rule

SICP Exercise 1.28 (Miller-Rabin Test)

SICP Exercise 4.18 a alternative strategy for interpreting internal definitions