this one busted me up a bit today
;exercise 2.20 - return numbers of same parity, arbitrary number of arguments (define (same-parity . x) (define (parity y) (modulo y 2)) (define (same-parity-recur x) (cond ((null? (cdr x)) x) ((= (parity (car x)) (parity (car (cdr x)))) (cons (car x) (same-parity-recur (cdr x)))) (else (same-parity-recur (cons (car x) (cdr (cdr x))))))) (same-parity-recur x))
although the ". x" takes a variable number of arguments and turns it into a list, it does not mean that you can pass in a list and have it do the right thing. and as far as i can tell, you can't decompose a list into atoms (since a function can't return more than one atom).
so therefore i have my hacky wrapper around what i think is a reasonably clever implementation of this, which results in:
(same-parity 1 2 3 4 5 6 7) (1 3 5 7) (same-parity 2 3 4 5 6 7) (2 4 6)
anyone have better suggestions? i probably [hopefully] just have a few gaps in my knowledge of scheme right now...


