開発環境
計算機プログラムの構造と解釈[第2版](ハロルド エイブルソン (著)、ジュリー サスマン (著)、ジェラルド・ジェイ サスマン (著)、Harold Abelson (原著)、Julie Sussman (原著)、Gerald Jay Sussman (原著)、和田 英一 (翻訳)、翔泳社、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の第4章(超言語的抽象)、4.1(超循環評価器)、4.1.6(内部定義)、問題4.21-a.を取り組んでみる。
その他参考書籍
- Instructor's Manual to Accompany Structure & Interpretation of Computer Programs
- プログラミングGauche (Kahuaプロジェクト (著), 川合 史朗 (監修), オライリージャパン)
- Scheme手習い
問題4.21-a.
コード(Emacs)
(begin
(define fibonacci-number
(lambda (n)
((lambda (proc)
(proc proc n))
(lambda (proc k)
(if (= k 0)
0
(if (= k 1)
1
(+ (proc proc (- k 1))
(proc proc (- k 2)))))))))
(define (print-fib start end)
(if (> start end)
'done
(begin (display (fibonacci-number start))
(newline)
(print-fib (+ start 1) end))))
(print-fib 0 10)
)
入出力結果(Terminal(kscheme), REPL(Read, Eval, Print, Loop))
$ kscheme < sample42_a.scm kscm> 0 1 1 2 3 5 8 13 21 34 55 done kscm> $
0 コメント:
コメントを投稿