2014年3月10日月曜日

開発環境

計算機プログラムの構造と解釈(Gerald Jay Sussman(原著)、Julie Sussman(原著)、Harold Abelson(原著)、和田 英一(翻訳)、ピアソンエデュケーション、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の2(データによる抽象の構築)、2.1(データ抽象入門)、2.1.4(拡張問題: 区間算術演算)、問題 2.7, 2.8を解いてみる。

その他参考書籍

問題 2.7, 2.8

コード(BBEdit, Emacs)

sample.scm

#!/usr/bin/env gosh
;; -*- coding: utf-8 -*-

;; これまでに書いた手続き
(load "./procedures.scm")

;; 選択子
(define (upper-bound x) (cdr x))

(define (lower-bound x) (car x))

;; 2つの区間の差
(define (sub-interval x y)
  (make-interval (- (lower-bound x) (upper-bound y))
                 (- (upper-bound x) (lower-bound y))))

(define intervals
  (fold (lambda (a acc)
          (append (map (lambda (b)
                         (make-interval a b))
                       '(-1 0 1 2))
                  acc))
        '()
        '(2 1 0 -1)))

(for-each (lambda (x)
            (for-each (lambda (y)
                        (print x ", " y ", "
                               (sub-interval x y)))
                      intervals))
          intervals)

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

$ ./sample.scm
(-1 . -1), (-1 . -1), (0 . 0)
(-1 . -1), (-1 . 0), (-1 . 0)
(-1 . -1), (-1 . 1), (-2 . 0)
(-1 . -1), (-1 . 2), (-3 . 0)
(-1 . -1), (0 . -1), (0 . -1)
(-1 . -1), (0 . 0), (-1 . -1)
(-1 . -1), (0 . 1), (-2 . -1)
(-1 . -1), (0 . 2), (-3 . -1)
(-1 . -1), (1 . -1), (0 . -2)
(-1 . -1), (1 . 0), (-1 . -2)
(-1 . -1), (1 . 1), (-2 . -2)
(-1 . -1), (1 . 2), (-3 . -2)
(-1 . -1), (2 . -1), (0 . -3)
(-1 . -1), (2 . 0), (-1 . -3)
(-1 . -1), (2 . 1), (-2 . -3)
(-1 . -1), (2 . 2), (-3 . -3)
(-1 . 0), (-1 . -1), (0 . 1)
(-1 . 0), (-1 . 0), (-1 . 1)
(-1 . 0), (-1 . 1), (-2 . 1)
(-1 . 0), (-1 . 2), (-3 . 1)
(-1 . 0), (0 . -1), (0 . 0)
(-1 . 0), (0 . 0), (-1 . 0)
(-1 . 0), (0 . 1), (-2 . 0)
(-1 . 0), (0 . 2), (-3 . 0)
(-1 . 0), (1 . -1), (0 . -1)
(-1 . 0), (1 . 0), (-1 . -1)
(-1 . 0), (1 . 1), (-2 . -1)
(-1 . 0), (1 . 2), (-3 . -1)
(-1 . 0), (2 . -1), (0 . -2)
(-1 . 0), (2 . 0), (-1 . -2)
(-1 . 0), (2 . 1), (-2 . -2)
(-1 . 0), (2 . 2), (-3 . -2)
(-1 . 1), (-1 . -1), (0 . 2)
(-1 . 1), (-1 . 0), (-1 . 2)
(-1 . 1), (-1 . 1), (-2 . 2)
(-1 . 1), (-1 . 2), (-3 . 2)
(-1 . 1), (0 . -1), (0 . 1)
(-1 . 1), (0 . 0), (-1 . 1)
(-1 . 1), (0 . 1), (-2 . 1)
(-1 . 1), (0 . 2), (-3 . 1)
(-1 . 1), (1 . -1), (0 . 0)
(-1 . 1), (1 . 0), (-1 . 0)
(-1 . 1), (1 . 1), (-2 . 0)
(-1 . 1), (1 . 2), (-3 . 0)
(-1 . 1), (2 . -1), (0 . -1)
(-1 . 1), (2 . 0), (-1 . -1)
(-1 . 1), (2 . 1), (-2 . -1)
(-1 . 1), (2 . 2), (-3 . -1)
(-1 . 2), (-1 . -1), (0 . 3)
(-1 . 2), (-1 . 0), (-1 . 3)
(-1 . 2), (-1 . 1), (-2 . 3)
(-1 . 2), (-1 . 2), (-3 . 3)
(-1 . 2), (0 . -1), (0 . 2)
(-1 . 2), (0 . 0), (-1 . 2)
(-1 . 2), (0 . 1), (-2 . 2)
(-1 . 2), (0 . 2), (-3 . 2)
(-1 . 2), (1 . -1), (0 . 1)
(-1 . 2), (1 . 0), (-1 . 1)
(-1 . 2), (1 . 1), (-2 . 1)
(-1 . 2), (1 . 2), (-3 . 1)
(-1 . 2), (2 . -1), (0 . 0)
(-1 . 2), (2 . 0), (-1 . 0)
(-1 . 2), (2 . 1), (-2 . 0)
(-1 . 2), (2 . 2), (-3 . 0)
(0 . -1), (-1 . -1), (1 . 0)
(0 . -1), (-1 . 0), (0 . 0)
(0 . -1), (-1 . 1), (-1 . 0)
(0 . -1), (-1 . 2), (-2 . 0)
(0 . -1), (0 . -1), (1 . -1)
(0 . -1), (0 . 0), (0 . -1)
(0 . -1), (0 . 1), (-1 . -1)
(0 . -1), (0 . 2), (-2 . -1)
(0 . -1), (1 . -1), (1 . -2)
(0 . -1), (1 . 0), (0 . -2)
(0 . -1), (1 . 1), (-1 . -2)
(0 . -1), (1 . 2), (-2 . -2)
(0 . -1), (2 . -1), (1 . -3)
(0 . -1), (2 . 0), (0 . -3)
(0 . -1), (2 . 1), (-1 . -3)
(0 . -1), (2 . 2), (-2 . -3)
(0 . 0), (-1 . -1), (1 . 1)
(0 . 0), (-1 . 0), (0 . 1)
(0 . 0), (-1 . 1), (-1 . 1)
(0 . 0), (-1 . 2), (-2 . 1)
(0 . 0), (0 . -1), (1 . 0)
(0 . 0), (0 . 0), (0 . 0)
(0 . 0), (0 . 1), (-1 . 0)
(0 . 0), (0 . 2), (-2 . 0)
(0 . 0), (1 . -1), (1 . -1)
(0 . 0), (1 . 0), (0 . -1)
(0 . 0), (1 . 1), (-1 . -1)
(0 . 0), (1 . 2), (-2 . -1)
(0 . 0), (2 . -1), (1 . -2)
(0 . 0), (2 . 0), (0 . -2)
(0 . 0), (2 . 1), (-1 . -2)
(0 . 0), (2 . 2), (-2 . -2)
(0 . 1), (-1 . -1), (1 . 2)
(0 . 1), (-1 . 0), (0 . 2)
(0 . 1), (-1 . 1), (-1 . 2)
(0 . 1), (-1 . 2), (-2 . 2)
(0 . 1), (0 . -1), (1 . 1)
(0 . 1), (0 . 0), (0 . 1)
(0 . 1), (0 . 1), (-1 . 1)
(0 . 1), (0 . 2), (-2 . 1)
(0 . 1), (1 . -1), (1 . 0)
(0 . 1), (1 . 0), (0 . 0)
(0 . 1), (1 . 1), (-1 . 0)
(0 . 1), (1 . 2), (-2 . 0)
(0 . 1), (2 . -1), (1 . -1)
(0 . 1), (2 . 0), (0 . -1)
(0 . 1), (2 . 1), (-1 . -1)
(0 . 1), (2 . 2), (-2 . -1)
(0 . 2), (-1 . -1), (1 . 3)
(0 . 2), (-1 . 0), (0 . 3)
(0 . 2), (-1 . 1), (-1 . 3)
(0 . 2), (-1 . 2), (-2 . 3)
(0 . 2), (0 . -1), (1 . 2)
(0 . 2), (0 . 0), (0 . 2)
(0 . 2), (0 . 1), (-1 . 2)
(0 . 2), (0 . 2), (-2 . 2)
(0 . 2), (1 . -1), (1 . 1)
(0 . 2), (1 . 0), (0 . 1)
(0 . 2), (1 . 1), (-1 . 1)
(0 . 2), (1 . 2), (-2 . 1)
(0 . 2), (2 . -1), (1 . 0)
(0 . 2), (2 . 0), (0 . 0)
(0 . 2), (2 . 1), (-1 . 0)
(0 . 2), (2 . 2), (-2 . 0)
(1 . -1), (-1 . -1), (2 . 0)
(1 . -1), (-1 . 0), (1 . 0)
(1 . -1), (-1 . 1), (0 . 0)
(1 . -1), (-1 . 2), (-1 . 0)
(1 . -1), (0 . -1), (2 . -1)
(1 . -1), (0 . 0), (1 . -1)
(1 . -1), (0 . 1), (0 . -1)
(1 . -1), (0 . 2), (-1 . -1)
(1 . -1), (1 . -1), (2 . -2)
(1 . -1), (1 . 0), (1 . -2)
(1 . -1), (1 . 1), (0 . -2)
(1 . -1), (1 . 2), (-1 . -2)
(1 . -1), (2 . -1), (2 . -3)
(1 . -1), (2 . 0), (1 . -3)
(1 . -1), (2 . 1), (0 . -3)
(1 . -1), (2 . 2), (-1 . -3)
(1 . 0), (-1 . -1), (2 . 1)
(1 . 0), (-1 . 0), (1 . 1)
(1 . 0), (-1 . 1), (0 . 1)
(1 . 0), (-1 . 2), (-1 . 1)
(1 . 0), (0 . -1), (2 . 0)
(1 . 0), (0 . 0), (1 . 0)
(1 . 0), (0 . 1), (0 . 0)
(1 . 0), (0 . 2), (-1 . 0)
(1 . 0), (1 . -1), (2 . -1)
(1 . 0), (1 . 0), (1 . -1)
(1 . 0), (1 . 1), (0 . -1)
(1 . 0), (1 . 2), (-1 . -1)
(1 . 0), (2 . -1), (2 . -2)
(1 . 0), (2 . 0), (1 . -2)
(1 . 0), (2 . 1), (0 . -2)
(1 . 0), (2 . 2), (-1 . -2)
(1 . 1), (-1 . -1), (2 . 2)
(1 . 1), (-1 . 0), (1 . 2)
(1 . 1), (-1 . 1), (0 . 2)
(1 . 1), (-1 . 2), (-1 . 2)
(1 . 1), (0 . -1), (2 . 1)
(1 . 1), (0 . 0), (1 . 1)
(1 . 1), (0 . 1), (0 . 1)
(1 . 1), (0 . 2), (-1 . 1)
(1 . 1), (1 . -1), (2 . 0)
(1 . 1), (1 . 0), (1 . 0)
(1 . 1), (1 . 1), (0 . 0)
(1 . 1), (1 . 2), (-1 . 0)
(1 . 1), (2 . -1), (2 . -1)
(1 . 1), (2 . 0), (1 . -1)
(1 . 1), (2 . 1), (0 . -1)
(1 . 1), (2 . 2), (-1 . -1)
(1 . 2), (-1 . -1), (2 . 3)
(1 . 2), (-1 . 0), (1 . 3)
(1 . 2), (-1 . 1), (0 . 3)
(1 . 2), (-1 . 2), (-1 . 3)
(1 . 2), (0 . -1), (2 . 2)
(1 . 2), (0 . 0), (1 . 2)
(1 . 2), (0 . 1), (0 . 2)
(1 . 2), (0 . 2), (-1 . 2)
(1 . 2), (1 . -1), (2 . 1)
(1 . 2), (1 . 0), (1 . 1)
(1 . 2), (1 . 1), (0 . 1)
(1 . 2), (1 . 2), (-1 . 1)
(1 . 2), (2 . -1), (2 . 0)
(1 . 2), (2 . 0), (1 . 0)
(1 . 2), (2 . 1), (0 . 0)
(1 . 2), (2 . 2), (-1 . 0)
(2 . -1), (-1 . -1), (3 . 0)
(2 . -1), (-1 . 0), (2 . 0)
(2 . -1), (-1 . 1), (1 . 0)
(2 . -1), (-1 . 2), (0 . 0)
(2 . -1), (0 . -1), (3 . -1)
(2 . -1), (0 . 0), (2 . -1)
(2 . -1), (0 . 1), (1 . -1)
(2 . -1), (0 . 2), (0 . -1)
(2 . -1), (1 . -1), (3 . -2)
(2 . -1), (1 . 0), (2 . -2)
(2 . -1), (1 . 1), (1 . -2)
(2 . -1), (1 . 2), (0 . -2)
(2 . -1), (2 . -1), (3 . -3)
(2 . -1), (2 . 0), (2 . -3)
(2 . -1), (2 . 1), (1 . -3)
(2 . -1), (2 . 2), (0 . -3)
(2 . 0), (-1 . -1), (3 . 1)
(2 . 0), (-1 . 0), (2 . 1)
(2 . 0), (-1 . 1), (1 . 1)
(2 . 0), (-1 . 2), (0 . 1)
(2 . 0), (0 . -1), (3 . 0)
(2 . 0), (0 . 0), (2 . 0)
(2 . 0), (0 . 1), (1 . 0)
(2 . 0), (0 . 2), (0 . 0)
(2 . 0), (1 . -1), (3 . -1)
(2 . 0), (1 . 0), (2 . -1)
(2 . 0), (1 . 1), (1 . -1)
(2 . 0), (1 . 2), (0 . -1)
(2 . 0), (2 . -1), (3 . -2)
(2 . 0), (2 . 0), (2 . -2)
(2 . 0), (2 . 1), (1 . -2)
(2 . 0), (2 . 2), (0 . -2)
(2 . 1), (-1 . -1), (3 . 2)
(2 . 1), (-1 . 0), (2 . 2)
(2 . 1), (-1 . 1), (1 . 2)
(2 . 1), (-1 . 2), (0 . 2)
(2 . 1), (0 . -1), (3 . 1)
(2 . 1), (0 . 0), (2 . 1)
(2 . 1), (0 . 1), (1 . 1)
(2 . 1), (0 . 2), (0 . 1)
(2 . 1), (1 . -1), (3 . 0)
(2 . 1), (1 . 0), (2 . 0)
(2 . 1), (1 . 1), (1 . 0)
(2 . 1), (1 . 2), (0 . 0)
(2 . 1), (2 . -1), (3 . -1)
(2 . 1), (2 . 0), (2 . -1)
(2 . 1), (2 . 1), (1 . -1)
(2 . 1), (2 . 2), (0 . -1)
(2 . 2), (-1 . -1), (3 . 3)
(2 . 2), (-1 . 0), (2 . 3)
(2 . 2), (-1 . 1), (1 . 3)
(2 . 2), (-1 . 2), (0 . 3)
(2 . 2), (0 . -1), (3 . 2)
(2 . 2), (0 . 0), (2 . 2)
(2 . 2), (0 . 1), (1 . 2)
(2 . 2), (0 . 2), (0 . 2)
(2 . 2), (1 . -1), (3 . 1)
(2 . 2), (1 . 0), (2 . 1)
(2 . 2), (1 . 1), (1 . 1)
(2 . 2), (1 . 2), (0 . 1)
(2 . 2), (2 . -1), (3 . 0)
(2 . 2), (2 . 0), (2 . 0)
(2 . 2), (2 . 1), (1 . 0)
(2 . 2), (2 . 2), (0 . 0)
$

0 コメント:

コメントを投稿