【SICP练习】52 练习2.20



练习2.20

如果读懂了题目的意思这道题也是不难的,重点就是带点尾部记法形式的define。下面我们就来写出same-parity过程。

(define (same-parity fist . other)

   (filter (if (even? fist)

                even?

             odd?)

          (cons first other)))

最巧妙地地方就在于用cons将散乱的firstother结合到一起,然后用filter来保留需要的部分,其中if返回的是谓词。

版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

posted @ 2015-02-22 13:48  nomasp  阅读(119)  评论(0编辑  收藏  举报