計算機プログラムの構造と解釈[第2版]
(翔泳社)
ハロルド エイブルソン (著)ジュリー サスマン (著)
ジェラルド・ジェイ サスマン (著)
Harold Abelson (原著)Julie Sussman (原著)
Gerald Jay Sussman (原著)和田 英一 (翻訳)
開発環境
- OS X Yosemite - 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))の1(手続きによる抽象の構築)、1.1(プログラムの要素)、1.1.6(条件式と述語)、問題 1.3.を解いてみる。
その他参考書籍
- Instructor's Manual to Accompany Structure & Interpretation of Computer Programs
- プログラミングGauche (Kahuaプロジェクト (著), 川合 史朗 (監修), オライリージャパン)
- Scheme手習い
問題 1.3.
コード(BBEdit, Emacs)
sample3.scm
#!/usr/bin/env gosh
;; -*- coding: utf-8 -*-
(define square (lambda (x) (* x x)))
(define >= (lambda (x y) (or (> x y) (= x y))))
(define (proc x y z)
(cond ((and (>= x z)
(>= y z))
(+ (square x)
(square y)))
((and (>= y x)
(>= z x))
(+ (square y)
(square z)))
(else (+ (square z) (square x)))))
(print (proc 1 1 1))
(print (proc 1 1 2))
(print (proc 1 2 1))
(print (proc 2 1 1))
(print (proc 1 2 3))
(print (proc 2 3 1))
(print (proc 3 1 2))
入出力結果(Terminal(gosh), REPL(Read, Eval, Print, Loop))
$ ./sample3.scm 2 5 5 5 13 13 13 $
0 コメント:
コメントを投稿