計算機プログラムの構造と解釈[第2版]
(翔泳社)
ハロルド エイブルソン (著) ジュリー サスマン (著)
ジェラルド・ジェイ サスマン (著)
Harold Abelson (原著) Julie Sussman (原著)
Gerald Jay Sussman (原著) 和田 英一 (翻訳)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Scheme (プログラミング言語)
- Gauche (処理系)
計算機プログラムの構造と解釈[第2版](ハロルド エイブルソン (著)、ジュリー サスマン (著)、ジェラルド・ジェイ サスマン (著)、Harold Abelson (原著)、Julie Sussman (原著)、Gerald Jay Sussman (原著)、和田 英一 (翻訳)、翔泳社、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の3(標準部品化力、オブジェクトおよび状態)、3.5(ストリーム)、3.5.2(無限ストリーム)、ストリームの暗黙の定義、問題 3.58.を解いてみる。
その他参考書籍
- Instructor's Manual to Accompany Structure & Interpretation of Computer Programs
- プログラミングGauche (Kahuaプロジェクト (著), 川合 史朗 (監修), オライリージャパン)
問題 3.58.
コード(BBEdit, Emacs)
sample58.scm
#!/usr/bin/env gosh
;; -*- coding: utf-8 -*-
(load "./stream.scm")
(define (enumerate-interval low high)
(if (> low high)
'()
(cons low
(enumerate-interval (+ low 1)
high))))
(define (expand num den radix)
(cons-stream
(quotient (* num radix) den)
(expand (remainder (* num radix) den) den radix)))
;; 1 4 2 8 5 7 1 4 2 8 5 7 ・・・
(define s1 (expand 1 7 10))
(for-each (lambda (n)
(print (stream-ref s1 n)))
(enumerate-interval 0 11))
;; 3 7 5 0 0 ・・・
(define s2 (expand 3 8 10))
(print)
(for-each (lambda (n)
(print (stream-ref s2 n)))
(enumerate-interval 0 10))
入出力結果(Terminal(gosh), REPL(Read, Eval, Print, Loop))
$ ./sample58.scm 1 4 2 8 5 7 1 4 2 8 5 7 3 7 5 0 0 0 0 0 0 0 0 $
0 コメント:
コメントを投稿