2014年2月27日木曜日

開発環境

計算機プログラムの構造と解釈(Gerald Jay Sussman(原著)、Julie Sussman(原著)、Harold Abelson(原著)、和田 英一(翻訳)、ピアソンエデュケーション、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の1(手続きによる抽象の構築)、1.3(高階手続きによる抽象)、1.3.4(値として返される手続き)、Newton法、抽象と第一級手続き、問題 1.41, 1.42.を解いてみる。

その他参考書籍

問題 1.41, 1.42.

コード(BBEdit, Emacs)

sample.scm

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

(define (inc x) (+ x 1))

(define (square x) (* x x))

(define (double f)
  (lambda (x)
    (f (f x))))

;; 3
(print "((double inc) 1): " ((double inc) 1))

;; 21
(print "(((double (double double)) inc) 5): "
       (((double (double double)) inc) 5))

(define (compose f g)
  (lambda (x)
    (f (g x))))

(print ((compose square inc) 6))

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

$ ./sample.scm
((double inc) 1): 3
(((double (double double)) inc) 5): 21
49
$

0 コメント:

コメントを投稿