; ======================================================================
;
; Structure and Interpretation of Computer Programs
; (trial answer to excercises)
;
; 计算机程序的构造和解释(习题试解)
;
; created: code17 07/28/05
; modified:
; (保持内容完整不变前提下,可以任意转载)
; ======================================================================
;; SICP No.2.25
(define (pick1 x)
(car (cdr (car (cdr (cdr x))))))
(define (pick2 x)
(car (car x)))
(define (pick3 x)
(define (cadr x) (car (cdr x)))
(cadr (cadr (cadr (cadr (cadr (cadr x)))))))
;; Test-it:
;; Welcome to MzScheme version 209, Copyright (c) 2004 PLT Scheme, Inc.
;; > (define e1 (list 1 3 (list 5 7) 9))
;; > e1
;; (1 3 (5 7) 9)
;; > (pick1 e1)
;; 7
;;
;; > (define e2 (list (list 7)))
;; > e2
;; ((7))
;; > (pick2 e2)
;; 7
;;
;; > (define e3 (list 1 (list 2 (list 3 (list 4 (list 5 (list 6 7)))))))
;; > e3
;; (1 (2 (3 (4 (5 (6 7))))))
;; > (pick3 e3)
;; 7