learning-sicp

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

exercise-21.scm (515B)


      1 ;; Exercise 2.21
      2 
      3 (define (exercise-2.21)
      4   (define (square-list-1 items)
      5     (if (null? items)
      6         '()
      7         (cons (* (car items)
      8                  (car items))
      9               (square-list-1 (cdr items)))))
     10 
     11   (define (square-list-2 items)
     12     (map (lambda (item)
     13            (* item
     14               item))
     15          items))
     16 
     17   (test-begin "2.21")
     18   (test-equal
     19       '(1 4 9 16)
     20     (square-list-1 '(1 2 3 4)))
     21   (test-equal
     22       '(1 4 9 16)
     23     (square-list-2 '(1 2 3 4)))
     24   (test-end "2.21"))
     25 
     26 (exercise-2.21)