SICPゼミ第10回

練習問題2.53
gosh> (list 'a 'b 'c)
(a b c)
gosh> (list (list 'george ))
((george))
gosh> (cdr '((x1 x2) (y1 y2)))
((y1 y2))
gosh> (cadr '((x1 x2) (y1 y2)))
(y1 y2)
gosh> (pair? (car '(a short list )))
#f
gosh> (memq 'red '((red shoes) (blue socks )))
#f
gosh> (memq 'red '(red shoes blue socks ))
(red shoes blue socks)

by pine

練習問題2.54
(define (equal? x y)
  (cond ((and (null? x) (null? y)) #t)
        ((or (null? x) (null? y)) #f)
        ((and (not (symbol? (car x))) (not (symbol? (car y)))) 
         (and (= (car x) (car y)) (equal? (cdr x) (cdr y))))
        (else (and (eq? (car x) (car y)) (equal? (cdr x) (cdr y))))))

by pine

練習問題2.55

f:id:sicp-zemi:20160426200735j:plain
'hogeみたいなのは内部でこんな感じで実装されてるんだと思う。リストの先頭の要素が"quote"でこれは記号データだよって示していて、その後ろにデータが来る。なのでcarすると"quote"が出力される。