「The Little Schemer」P.7 ~
- The Law of Cons       - The primitive cons takes two arguments.The second argument to cons must be a list.the result is a list.
- 組み込み手続きconsは2つの引数を取る。第二引数は必ずlistでなければならない。結果もlistとなる。
 
| (cons 'peanut '(butter and jelly)) ;; => (peanut butter and jelly) | 
- cons手続きはlistの先頭にatomを追加する
- 読み      - cons the atom peanut onto the list (butter and jelly)
 
| (cons '(banana and) '(peanut butter and jelly)) ;; => ((banana and) peanut butter and jelly) | 
- cons手続きはlistの先頭にS式を追加する
| (cons '((help) this) '(is very ((hard) to learn))) ;; => (((help) this) is very ((hard) to learn)) | 
- cons手続きは2つの手続きを取る       - 第一引数にはなんらかのS式
- 第二引数にはなんらかのlist
 
| (cons '(a b (c)) '()) ;; => ((a b (c))) | 
- ()はlistであるから
| (cons a '()) ;; => (a) | 
| (cons '((a b c)) 'b) ;; => (((a b c)) . b) | 
- The Little Schemerでは・・・       - No Answer, since the second argument l must be a list.
- 回答なし、第二引数は必ずlistでなければならない          - Gaucheでは対(つい)が返る               - (((a b c)) . b)
 
 
- Gaucheでは対(つい)が返る               
 
- In practice      - (cons a b) works for all values a and b
- (car (cons a b)) = a
- (cdr (cons a b)) = b
 
では、No Answerとはどういうこと?
| (cons 'a 'b) | 
- No Answer, Why?      - 取り合えず回答          - Because the second argument must be a list.
- 第二引数はlistでなければならないため              - でも・・・対は?
 
 
 
- 取り合えず回答          
| (cons 'a (car'((b) c d))) ;; => (a b) | 
- Why?      - (car '((b) c d))          - (b)
 
- (cons 'a '(b))           - (a b)
 
 
- (car '((b) c d))          
| (cons 'a '((b) c d)) ;; => (a c d) | 
- Why?        - (cdr '((b) c d))            - (c d)
 
- (cons 'a '(c d))             - (a c d)
 
 
- (cdr '((b) c d))            
 
0 件のコメント:
コメントを投稿