; ====================================================================== ; ; Structure and Interpretation of Computer Programs ; (trial answer to excercises) ; ; 计算机程序的构造和解释(习题试解) ; ; created: code17 07/14/05 ; modified: ; (保持内容完整不变前提下,可以任意转载) ; ======================================================================
;; SICP No.2.20 (define (same-parity a . z) (define parity (if (odd? a) odd? even?)) (define (filter l) (cond ((null? l) l) ((parity (car l)) (cons (car l) (filter (cdr l)))) (else (filter (cdr l))))) (cons a (filter z)))
;; Test-it: ;; Welcome to MzScheme version 209, Copyright (c) 2004 PLT Scheme, Inc. ;; > (same-parity 1 2 3 4 5 6 7) ;; (1 3 5 7) ;; > (same-parity 2 3 4 5 6 7) ;; (2 4 6)
|