learning-sicp

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

exercise-54.scm (892B)


      1 
      2 (define (exercise-2.54)
      3   (define (my-equal? a b)
      4     (cond
      5      ((and (null? a)
      6            (null? b))
      7       #t)
      8      ((and (symbol? a)
      9            (symbol? b))
     10       (eq? a
     11            b))
     12      ((and (pair? a)
     13            (pair? b))
     14       (and (my-equal? (car a)
     15                       (car b))
     16            (my-equal? (cdr a)
     17                       (cdr b))))
     18      (else #f)))
     19 
     20   (test-begin "2.54")
     21   (test-equal
     22       #t
     23     (my-equal? 'a 'a))
     24   (test-equal
     25       #f
     26     (my-equal? 'a 'b))
     27   (test-equal
     28       #f
     29     (my-equal? '(a) 'b))
     30   (test-equal
     31       #t
     32     (my-equal? '(a) '(a)))
     33   (test-equal
     34       #t
     35     (my-equal? '((a b c ((d e) f) g h)) '((a b c ((d e) f) g h))))
     36   (test-equal
     37       #f
     38     (my-equal? '((a b c ((d e) f) g h)) '((a b c (d e f) g h))))
     39   (test-equal
     40       #f
     41     (my-equal? '((a b c ((d e) f) g h)) '((a b c ((d d) f) g h))))
     42   (test-end "2.54"))
     43 
     44 (exercise-2.54)