関数型言語の勉強に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

だから。


※「SICPを読もう」の目次はこちら


計算機プログラムの構造と解釈
Gerald Jay Sussman Julie Sussman Harold Abelson 和田 英一
ピアソンエデュケーション (2000/02)
売り上げランキング: 56,404

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy