開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Scheme (プログラミング言語)
- Gauche (処理系)
計算機プログラムの構造と解釈(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.12.を解いてみる。
その他参考書籍
- Instructor's Manual to Accompany Structure & Interpretation of Computer Programs
- プログラミングGauche (Kahuaプロジェクト (著), 川合 史朗 (監修), オライリージャパン)
問題 2.12.
コード(BBEdit, Emacs)
sample.scm
#!/usr/bin/env gosh
;; -*- coding: utf-8 -*-
;; これまでに書いた手続き
(load "./procedures.scm")
;; 構成子
;; 区間の中央値とパーセント相対許容誤差
(define (make-center-percent c p)
((lambda (x)
(make-interval (- c x)
(+ c x)))
(* (abs c)
(/ p 100))))
;; 選択子
;; パーセント相対許容誤差
(define (percent i)
((lambda (c)
(abs (* 100
(/ (- (upper-bound i)
c)
c))))
(center i)))
;; テスト
(define interval (make-center-percent 100 10))
(for-each (lambda (p)
(print (car p)
(cdr p)))
(list (cons "区間: "
interval)
(cons "最小値: "
(lower-bound interval))
(cons "最大値: "
(upper-bound interval))
(cons "中央値: "
(center interval))
(cons "幅: "
(width interval))
(cons "パーセント相対許容誤差(%): "
(percent interval))))
入出力結果(Terminal(gosh), REPL(Read, Eval, Print, Loop))
$ ./sample.scm 区間: (90 . 110) 最小値: 90 最大値: 110 中央値: 100 幅: 10 パーセント相対許容誤差(%): 10 $
0 コメント:
コメントを投稿