learning-sicp

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

exercise-13.scm (1390B)


      1 (define-library (sicp tests chapter-4 exercise-13)
      2   (import (scheme base)
      3 
      4           (srfi :64)
      5 
      6           (sicp solutions chapter-4 exercise-13)
      7 
      8           (sicp utils))
      9 
     10   (begin
     11     ;; (debug! #t)
     12 
     13     ;; TODO: Not sure if this is the real solution.
     14 
     15     (test-begin "chapter-4-exercise-13")
     16 
     17     (test-equal 1
     18       (eval '1
     19             (setup-environment)))
     20 
     21     (test-equal 1
     22       (eval '(begin
     23                (define a 1)
     24                1)
     25             (setup-environment)))
     26 
     27     (test-equal 1
     28       (eval '(begin
     29                (define a 1)
     30                (let ((b 1))
     31                  b))
     32             (setup-environment)))
     33 
     34     (test-equal 1
     35       (eval '(begin
     36                (define a 1)
     37                (let* ((b 1))
     38                  b))
     39             (setup-environment)))
     40 
     41     (test-equal 2
     42       (eval '(begin
     43                (define a 1)
     44                (+ a 1))
     45             (setup-environment)))
     46 
     47     (test-equal 3
     48       (eval '(begin
     49                (define a 1)
     50                (let ((b (+ a 1)))
     51                  (+ a b)))
     52             (setup-environment)))
     53 
     54     (test-equal 5
     55       (eval '(begin
     56                (define a 1) ;; a = 1
     57                (let ((b (+ a 1))) ;; b = 1 + 1 = 2
     58                  (set! b (+ b b)) ;; b = b + b = 2 + 2 = 4
     59                  (+ a b))) ;; a = a + b = 1 + 4 = 5
     60             (setup-environment)))
     61 
     62     (test-end "chapter-4-exercise-13")
     63     ))