; ======================================================================
;
; Structure and Interpretation of Computer Programs
; (trial answer to excercises)
;
; 计算机程序的构造和解释(习题试解)
;
; created: code17 04/23/05
; modified:
; (保持内容完整不变前提下,可以任意转载)
; ======================================================================
;; SICP No.2.4
;; cdr可定义为
(define (cdr z)
(z (lambda (p q) q)))
;; 验证
;; (car (cons x y))
;; => (car (lambda (m) (m x y)))
;; => ((lambda (m) (m x y)) (lambda (p q) p))
;; => ((lambda (p q) p) x y)
;; => x
;;
;; cdr同理
;; Test-it:
;; Welcome to MzScheme version 209, Copyright (c) 2004 PLT Scheme, Inc.
;; > (define test12 (cons 1 2))
;; > (car test12)
;; 1
;; > (cdr test12)
;; 2
;; > (define test123 (cons test12 3))
;; > (cdr test123)
;; 3
;; > (car test123)
;; #<procedure:STDIN::21>
;; > (cdr (car test123))
;; 2