learning-sicp

My embarrassing half assed SICP run.
git clone https://kaka.farm/~git/learning-sicp
Log | Files | Refs

exercise-28.scm (543B)


      1 ;; Exercise 2.28
      2 
      3 (define (exercise-2.28)
      4   (define (fringe a-tree)
      5     (cond
      6      ((null? a-tree) '())
      7      ((pair? a-tree)
      8       (cond
      9        ((pair? (car a-tree))
     10         (append (fringe (car a-tree))
     11                 (fringe (cdr a-tree))))
     12        (else (cons (car a-tree)
     13                    (fringe (cdr a-tree))))))
     14      (else a-tree)))
     15 
     16   (define x '((1 2) (3 4)))
     17 
     18   (test-begin "2.28")
     19   (test-equal
     20       '(1 2 3 4)
     21     (fringe x))
     22   (test-equal
     23       '(1 2 3 4 1 2 3 4)
     24     (fringe (list x x)))
     25   (test-end "2.28"))
     26 
     27 (exercise-2.28)