開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Scheme (プログラミング言語)
- Gauche (処理系)
計算機プログラムの構造と解釈(Gerald Jay Sussman(原著)、Julie Sussman(原著)、Harold Abelson(原著)、和田 英一(翻訳)、ピアソンエデュケーション、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の2(データによる抽象の構築)、2.2(階層データ構造と閉包性)、2.2.3(公認インターフェースとしての並び)、並びの演算、問題 2.33.を解いてみる。
その他参考書籍
- Instructor's Manual to Accompany Structure & Interpretation of Computer Programs
- プログラミングGauche (Kahuaプロジェクト (著), 川合 史朗 (監修), オライリージャパン)
問題 2.33.
コード(BBEdit, Emacs)
sample.scm
#!/usr/bin/env gosh
;; -*- coding: utf-8 -*-
;; これまでに書いた手続き
(load "./procedures.scm")
(define (map proc sequence)
(accumulate (lambda (x y)
(cons (proc x) y))
nil
sequence))
(define (append seq1 seq2)
(accumulate cons seq2 seq1))
(define (length sequence)
(accumulate (lambda (x y)
(+ 1 y))
0
sequence))
(for-each print
(list (map square (list 1 2 3 4 5))
(append '(1 2) '(3 4))
(append (list 1 (list 2))
(list (list 3) 4))
(length (list 1 2 3 4 5))
(length (list 1 (list 2 3) 4 5))))
入出力結果(Terminal(gosh), REPL(Read, Eval, Print, Loop))
$ ./sample.scm (1 4 9 16 25) (1 2 3 4) (1 (2) (3) 4) 5 4 $
0 コメント:
コメントを投稿