開発環境
- 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.5(汎用演算のシステム)、2.5.1(汎用算術演算)、問題 2.79.を解いてみる。
その他参考書籍
- Instructor's Manual to Accompany Structure & Interpretation of Computer Programs
- プログラミングGauche (Kahuaプロジェクト (著), 川合 史朗 (監修), オライリージャパン)
問題 2.79.
コード(BBEdit, Emacs)
sample.scm
#!/usr/bin/env gosh
;; -*- coding: utf-8 -*-
;; scheme数パッケージに追加
(put 'equ? '(scheme-number scheme-number)
(lambda (x y) (= x y)))
;; 有理数パッケージに追加
(define (equ-rat? x y)
(and (= (numer x)
(numer y))
(= (denom x)
(denom y))))
(put 'equ? '(rational rational)
(lambda (x y)
(equ-rat? x y)))
;; 複素数パッケージに追加
(define (equ-complex? x y)
(and (= (real-part x)
(real-part y))
(= (imag-part x)
(imag-part y))))
(put 'equ? '(complex complex)
(lambda (x y)
(equ-complex? x y)))
(define (equ? x y)
(apply-generic 'equ? x y))
0 コメント:
コメントを投稿