exercise-20.scm (660B)
1 ;; Exercise 2.20 2 3 (define (same-arity n . ns) 4 (define (same-arity' n ns) 5 (cond 6 ((null? ns) 7 (list n)) 8 ((or (and (even? n) 9 (even? (car ns))) 10 (and (odd? n) 11 (odd? (car ns)))) 12 (cons n 13 (same-arity' (car ns) 14 (cdr ns)))) 15 (else 16 (cons n 17 (same-arity' (cadr ns) 18 (cddr ns)))))) 19 (same-arity' n ns)) 20 21 22 (test-begin "2.20") 23 (test-equal 24 '(1 3 5 7) 25 (same-arity 1 2 3 4 5 6 7)) 26 (test-equal 27 '(2 4 6 8) 28 (same-arity 2 3 4 5 6 7 8)) 29 (test-equal '(1) (same-arity 1)) 30 (test-equal '(2) (same-arity 2)) 31 (test-end "2.20")