learning-sicp

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

exercise-24.scm (1503B)


      1 ;; Exercise 2.24
      2 
      3 ;; scheme@(guile-user)> (list 1 (list 2 (list 3 4)))
      4 ;; $1 = (1 (2 (3 4)))
      5 
      6 ;; -----> [1 |]
      7 ;;           |
      8 ;;           \--> [| ()]
      9 ;;                 |
     10 ;;                 \-> [2 |]
     11 ;;                        |
     12 ;;                        \-> [| ()]
     13 ;;                             |
     14 ;;                             \-> [3 |]
     15 ;;                                    |
     16 ;;                                    \-> [4 ()]
     17 
     18 ;; (1 (2 (3 4)))
     19 ;;      /\
     20 ;;     1  (2 (3 4))
     21 ;;           /\
     22 ;;          2  (3 4)
     23 ;;              /\
     24 ;;             3  4
     25 
     26 (let* ([xs-34 (list 3 4)]
     27        [xs-234 (list 2 xs-34)]
     28        [xs-1234 (list 1 xs-234)])
     29   (test-begin "2.24")
     30   (test-equal
     31       (list 1
     32             (list 2
     33                   (list 3
     34                         4)))
     35     (cons 1
     36           (cons (cons 2
     37                       (cons (cons 3
     38                                   (cons 4
     39                                         '()))
     40                             '()))
     41                 '())))
     42   (test-equal
     43       (list 1
     44             (list 2
     45                   (list 3
     46                         4)))
     47     '(1 . ((2 . ((3 . (4 . ())) . ())) . ())))
     48   (test-equal
     49       (list 1 (list 2 (list 3 4)))
     50     (cons 1
     51           (cons (cons 2
     52                       (cons xs-34
     53                             '()))
     54                 '())))
     55   (test-equal
     56       (list 1 (list 2 (list 3 4)))
     57     (cons 1
     58           (cons xs-234
     59                 '())))
     60   (test-equal
     61       (list 1 (list 2 (list 3 4)))
     62     xs-1234)
     63   (test-end "2.24"))