I am new to Scheme, and I am learning SICP now. I write some code for Exercise 2.20, to return a list whose element shares the same parity with the first one:
(define (same-parity first . rest)
(define (same-parity-iter ret rest)
(if (null? rest)
ret
((if (odd? (+ first (car rest)))
(same-parity-iter ret (cdr rest))
(same-parity-iter (append ret (list (car rest))) (cdr rest))))))
(same-parity-iter (list first) (cdr rest)))
and run it with some example:
(same-parity 1 2 3 4 5)
then there is the error:
The object (1 3 5) is not applicable.
Do you know how to fix this error? I guess it treats the return value (1 3 5) as a function, but have no idea how to fix it. Thank you.