1 (define (test-case actual expected)
10 (define (deep-reverse tree)
11 (cond ((null? tree) '())
12 ((not (pair? tree)) tree)
14 (deep-reverse (cdr tree))
15 (list (deep-reverse (car tree)))))))
17 ;; (define x (list (list 1 2) (list 3 4)))
18 ;; (test-case (reverse x) '((3 4) (1 2)))
19 ;; (test-case (deep-reverse x) '((4 3) (2 1)))
22 ;;Exercise 2.28. Write a procedure fringe that takes as argument a tree (represented as a list) and returns a list whose elements are all the leaves of the tree arranged in left-to-right order. For example,
25 (cond ((null? tree) '())
26 ((not (pair? tree)) (list tree))
27 (else (append (fringe (car tree))
28 (fringe (cdr tree))))))
31 (define x (list (list 1 2) (list 3 4)))
32 (test-case (fringe x) '(1 2 3 4))
33 (test-case (fringe (list x x)) '(1 2 3 4 1 2 3 4))