関数型言語の勉強にSICPを読もう - (19) 2章 - データによる抽象の構築 - 2.3.1 (83-85ページ)
2.3.1クォート
今まではデータは数値だけでしたが、クォートが登場しました。
問題2.53
(list 'a 'b 'c) gosh> (a b c) (list (list 'george)) gosh> ((george)) (cdr '((x1 x2) (y1 y2))) gosh> ((y1 y2)) (cadr '((x1 x2) (y1 y2))) gosh> (y1 y2) (pair? (car '(a short list))) gosh> #f (memq 'red '((red shoes) (blue socks))) #f (memq 'red '(red shoes blues socks)) gosh> (red shoes blues socks)
問題2.54
要素をひとつずつ取り出し eq? する。
頭の中にあったの eq? の結果がfalseならすぐにfalseを返すものだが気づいたら and をとっていた。
(define (equal? list1 list2) (cond ((and (null? list1) (null? list2)) #t) ((null? list1) #f) ((null? list2) #f) (else (and (eq? (car list1) (car list2)) (equal? (cdr list1) (cdr list2)))))) (equal? '(this is a list) '(this is a list)) (equal? '(this is a list) '(this (is a) list))
問題2.55
(quoate (quoate
だから。
計算機プログラムの構造と解釈
posted with amazlet on 06.04.15
Gerald Jay Sussman Julie Sussman Harold Abelson 和田 英一
ピアソンエデュケーション (2000/02)
売り上げランキング: 56,404
ピアソンエデュケーション (2000/02)
売り上げランキング: 56,404