2015年4月5日日曜日

開発環境

計算機プログラムの構造と解釈[第2版](ハロルド エイブルソン (著)、ジュリー サスマン (著)、ジェラルド・ジェイ サスマン (著)、Harold Abelson (原著)、Julie Sussman (原著)、Gerald Jay Sussman (原著)、和田 英一 (翻訳)、翔泳社、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の2(データによる抽象の構築)、2.2(階層データ構造と閉包性)、2.2.1(並びの表現)、問題 2.20.を解いてみる。

その他参考書籍

問題 2.20.

コード(BBEdit, Emacs)

(define same-parity
  (lambda (g . w)
    (define iter
      (lambda (f items)
        (cond ((null? items) (list))
              ((f (car items)) (cons (car items)
                                     (iter f (cdr items))))
              (else (iter f (cdr items))))))
    (if (even? g)
        (cons g (iter even? w))
        (cons g (iter odd? w)))))

(print (same-parity 1 2 3 4 5 6 7))
(print (same-parity 2 3 4 5 6 7))

入出力結果(Terminal(kscheme), REPL(Read, Eval, Print, Loop))

$ gosh sample20.scm
(1 3 5 7)
(2 4 6)
$

0 コメント:

コメントを投稿