2015年1月21日水曜日

開発環境

計算機プログラムの構造と解釈[第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.4.を解いてみる。

その他参考書籍

問題 1.4.

コード(BBEdit, Emacs)

sample4.scm

#!/usr/bin/env gosh
;; -*- coding: utf-8 -*-

(define (a-plus-abs-b a b)
  ((if (> b 0) + -) a b))

(for-each (lambda (x)
            (print x))
          (list (a-plus-abs-b -5 10)
                ((if (> 10 0) + -) -5 10)
                ((if #t + -) -5 10)
                (+ -5 10)
                5
                (a-plus-abs-b 5 -10)
                ((if (> -10 0) + -) 5 -10)
                ((if #f + -) 5 -10)
                (- 5 -10)
                15))
                
                      

入出力結果(Terminal(gosh), REPL(Read, Eval, Print, Loop))

$ ./sample4.scm
5
5
5
5
5
15
15
15
15
15
$

0 コメント:

コメントを投稿