開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Scheme (プログラミング言語)
- Gauche (処理系)
- Racket (プログラミング言語)
- DrRacket (開発環境)
計算機プログラムの構造と解釈(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.4(例: 図形言語)、フレーム、問題 2.47.を解いてみる。
その他参考書籍
- Instructor's Manual to Accompany Structure & Interpretation of Computer Programs
- プログラミングGauche (Kahuaプロジェクト (著), 川合 史朗 (監修), オライリージャパン)
問題 2.47.
コード(BBEdit, Emacs)
sample.scm
#!/usr/bin/env gosh ;; -*- coding: utf-8 -*- ;; これまでに書いた手続き (load "./procedures.scm") (define (make-frame origin edge1 edge2) (list origin edge1 edge2)) (define (origin-frame frame) (car frame)) (define (edge1-frame frame) (car (cdr frame))) (define (edge2-frame frame) (car (cdr (cdr frame)))) (define (make-frame1 origin edge1 edge2) (cons origin (cons edge1 edge2))) (define (origin-frame1 frame) (car frame)) (define (edge1-frame1 frame) (car (cdr frame))) (define (edge2-frame1 frame) (cdr (cdr frame))) (define v1 (make-vect 0 0)) (define v2 (make-vect 1 1)) (define v3 (make-vect 2 3)) (define v4 (make-vect 4 5)) (define vectors (list v1 v2 v3 v4)) (define frames (flatmap (lambda (origin) (flatmap (lambda (edge1) (map (lambda (edge2) (make-frame origin edge1 edge2)) vectors)) vectors)) vectors)) (define frames1 (flatmap (lambda (origin) (flatmap (lambda (edge1) (map (lambda (edge2) (make-frame1 origin edge1 edge2)) vectors)) vectors)) vectors)) (for-each (lambda (frame) (print "frame:" frame " origin:" (origin-frame frame) " edge1:" (edge1-frame frame) " edge2:" (edge2-frame frame))) frames) (for-each (lambda (frame1) (print "frame1:" frame1 " origin:" (origin-frame1 frame1) " edge1:" (edge1-frame1 frame1) " edge2:" (edge2-frame1 frame1))) frames1)
入出力結果(Terminal(gosh), REPL(Read, Eval, Print, Loop))
$ ./sample.scm frame:((0 0) (0 0) (0 0)) origin:(0 0) edge1:(0 0) edge2:(0 0) frame:((0 0) (0 0) (1 1)) origin:(0 0) edge1:(0 0) edge2:(1 1) frame:((0 0) (0 0) (2 3)) origin:(0 0) edge1:(0 0) edge2:(2 3) frame:((0 0) (0 0) (4 5)) origin:(0 0) edge1:(0 0) edge2:(4 5) frame:((0 0) (1 1) (0 0)) origin:(0 0) edge1:(1 1) edge2:(0 0) frame:((0 0) (1 1) (1 1)) origin:(0 0) edge1:(1 1) edge2:(1 1) frame:((0 0) (1 1) (2 3)) origin:(0 0) edge1:(1 1) edge2:(2 3) frame:((0 0) (1 1) (4 5)) origin:(0 0) edge1:(1 1) edge2:(4 5) frame:((0 0) (2 3) (0 0)) origin:(0 0) edge1:(2 3) edge2:(0 0) frame:((0 0) (2 3) (1 1)) origin:(0 0) edge1:(2 3) edge2:(1 1) frame:((0 0) (2 3) (2 3)) origin:(0 0) edge1:(2 3) edge2:(2 3) frame:((0 0) (2 3) (4 5)) origin:(0 0) edge1:(2 3) edge2:(4 5) frame:((0 0) (4 5) (0 0)) origin:(0 0) edge1:(4 5) edge2:(0 0) frame:((0 0) (4 5) (1 1)) origin:(0 0) edge1:(4 5) edge2:(1 1) frame:((0 0) (4 5) (2 3)) origin:(0 0) edge1:(4 5) edge2:(2 3) frame:((0 0) (4 5) (4 5)) origin:(0 0) edge1:(4 5) edge2:(4 5) frame:((1 1) (0 0) (0 0)) origin:(1 1) edge1:(0 0) edge2:(0 0) frame:((1 1) (0 0) (1 1)) origin:(1 1) edge1:(0 0) edge2:(1 1) frame:((1 1) (0 0) (2 3)) origin:(1 1) edge1:(0 0) edge2:(2 3) frame:((1 1) (0 0) (4 5)) origin:(1 1) edge1:(0 0) edge2:(4 5) frame:((1 1) (1 1) (0 0)) origin:(1 1) edge1:(1 1) edge2:(0 0) frame:((1 1) (1 1) (1 1)) origin:(1 1) edge1:(1 1) edge2:(1 1) frame:((1 1) (1 1) (2 3)) origin:(1 1) edge1:(1 1) edge2:(2 3) frame:((1 1) (1 1) (4 5)) origin:(1 1) edge1:(1 1) edge2:(4 5) frame:((1 1) (2 3) (0 0)) origin:(1 1) edge1:(2 3) edge2:(0 0) frame:((1 1) (2 3) (1 1)) origin:(1 1) edge1:(2 3) edge2:(1 1) frame:((1 1) (2 3) (2 3)) origin:(1 1) edge1:(2 3) edge2:(2 3) frame:((1 1) (2 3) (4 5)) origin:(1 1) edge1:(2 3) edge2:(4 5) frame:((1 1) (4 5) (0 0)) origin:(1 1) edge1:(4 5) edge2:(0 0) frame:((1 1) (4 5) (1 1)) origin:(1 1) edge1:(4 5) edge2:(1 1) frame:((1 1) (4 5) (2 3)) origin:(1 1) edge1:(4 5) edge2:(2 3) frame:((1 1) (4 5) (4 5)) origin:(1 1) edge1:(4 5) edge2:(4 5) frame:((2 3) (0 0) (0 0)) origin:(2 3) edge1:(0 0) edge2:(0 0) frame:((2 3) (0 0) (1 1)) origin:(2 3) edge1:(0 0) edge2:(1 1) frame:((2 3) (0 0) (2 3)) origin:(2 3) edge1:(0 0) edge2:(2 3) frame:((2 3) (0 0) (4 5)) origin:(2 3) edge1:(0 0) edge2:(4 5) frame:((2 3) (1 1) (0 0)) origin:(2 3) edge1:(1 1) edge2:(0 0) frame:((2 3) (1 1) (1 1)) origin:(2 3) edge1:(1 1) edge2:(1 1) frame:((2 3) (1 1) (2 3)) origin:(2 3) edge1:(1 1) edge2:(2 3) frame:((2 3) (1 1) (4 5)) origin:(2 3) edge1:(1 1) edge2:(4 5) frame:((2 3) (2 3) (0 0)) origin:(2 3) edge1:(2 3) edge2:(0 0) frame:((2 3) (2 3) (1 1)) origin:(2 3) edge1:(2 3) edge2:(1 1) frame:((2 3) (2 3) (2 3)) origin:(2 3) edge1:(2 3) edge2:(2 3) frame:((2 3) (2 3) (4 5)) origin:(2 3) edge1:(2 3) edge2:(4 5) frame:((2 3) (4 5) (0 0)) origin:(2 3) edge1:(4 5) edge2:(0 0) frame:((2 3) (4 5) (1 1)) origin:(2 3) edge1:(4 5) edge2:(1 1) frame:((2 3) (4 5) (2 3)) origin:(2 3) edge1:(4 5) edge2:(2 3) frame:((2 3) (4 5) (4 5)) origin:(2 3) edge1:(4 5) edge2:(4 5) frame:((4 5) (0 0) (0 0)) origin:(4 5) edge1:(0 0) edge2:(0 0) frame:((4 5) (0 0) (1 1)) origin:(4 5) edge1:(0 0) edge2:(1 1) frame:((4 5) (0 0) (2 3)) origin:(4 5) edge1:(0 0) edge2:(2 3) frame:((4 5) (0 0) (4 5)) origin:(4 5) edge1:(0 0) edge2:(4 5) frame:((4 5) (1 1) (0 0)) origin:(4 5) edge1:(1 1) edge2:(0 0) frame:((4 5) (1 1) (1 1)) origin:(4 5) edge1:(1 1) edge2:(1 1) frame:((4 5) (1 1) (2 3)) origin:(4 5) edge1:(1 1) edge2:(2 3) frame:((4 5) (1 1) (4 5)) origin:(4 5) edge1:(1 1) edge2:(4 5) frame:((4 5) (2 3) (0 0)) origin:(4 5) edge1:(2 3) edge2:(0 0) frame:((4 5) (2 3) (1 1)) origin:(4 5) edge1:(2 3) edge2:(1 1) frame:((4 5) (2 3) (2 3)) origin:(4 5) edge1:(2 3) edge2:(2 3) frame:((4 5) (2 3) (4 5)) origin:(4 5) edge1:(2 3) edge2:(4 5) frame:((4 5) (4 5) (0 0)) origin:(4 5) edge1:(4 5) edge2:(0 0) frame:((4 5) (4 5) (1 1)) origin:(4 5) edge1:(4 5) edge2:(1 1) frame:((4 5) (4 5) (2 3)) origin:(4 5) edge1:(4 5) edge2:(2 3) frame:((4 5) (4 5) (4 5)) origin:(4 5) edge1:(4 5) edge2:(4 5) frame1:((0 0) (0 0) 0 0) origin:(0 0) edge1:(0 0) edge2:(0 0) frame1:((0 0) (0 0) 1 1) origin:(0 0) edge1:(0 0) edge2:(1 1) frame1:((0 0) (0 0) 2 3) origin:(0 0) edge1:(0 0) edge2:(2 3) frame1:((0 0) (0 0) 4 5) origin:(0 0) edge1:(0 0) edge2:(4 5) frame1:((0 0) (1 1) 0 0) origin:(0 0) edge1:(1 1) edge2:(0 0) frame1:((0 0) (1 1) 1 1) origin:(0 0) edge1:(1 1) edge2:(1 1) frame1:((0 0) (1 1) 2 3) origin:(0 0) edge1:(1 1) edge2:(2 3) frame1:((0 0) (1 1) 4 5) origin:(0 0) edge1:(1 1) edge2:(4 5) frame1:((0 0) (2 3) 0 0) origin:(0 0) edge1:(2 3) edge2:(0 0) frame1:((0 0) (2 3) 1 1) origin:(0 0) edge1:(2 3) edge2:(1 1) frame1:((0 0) (2 3) 2 3) origin:(0 0) edge1:(2 3) edge2:(2 3) frame1:((0 0) (2 3) 4 5) origin:(0 0) edge1:(2 3) edge2:(4 5) frame1:((0 0) (4 5) 0 0) origin:(0 0) edge1:(4 5) edge2:(0 0) frame1:((0 0) (4 5) 1 1) origin:(0 0) edge1:(4 5) edge2:(1 1) frame1:((0 0) (4 5) 2 3) origin:(0 0) edge1:(4 5) edge2:(2 3) frame1:((0 0) (4 5) 4 5) origin:(0 0) edge1:(4 5) edge2:(4 5) frame1:((1 1) (0 0) 0 0) origin:(1 1) edge1:(0 0) edge2:(0 0) frame1:((1 1) (0 0) 1 1) origin:(1 1) edge1:(0 0) edge2:(1 1) frame1:((1 1) (0 0) 2 3) origin:(1 1) edge1:(0 0) edge2:(2 3) frame1:((1 1) (0 0) 4 5) origin:(1 1) edge1:(0 0) edge2:(4 5) frame1:((1 1) (1 1) 0 0) origin:(1 1) edge1:(1 1) edge2:(0 0) frame1:((1 1) (1 1) 1 1) origin:(1 1) edge1:(1 1) edge2:(1 1) frame1:((1 1) (1 1) 2 3) origin:(1 1) edge1:(1 1) edge2:(2 3) frame1:((1 1) (1 1) 4 5) origin:(1 1) edge1:(1 1) edge2:(4 5) frame1:((1 1) (2 3) 0 0) origin:(1 1) edge1:(2 3) edge2:(0 0) frame1:((1 1) (2 3) 1 1) origin:(1 1) edge1:(2 3) edge2:(1 1) frame1:((1 1) (2 3) 2 3) origin:(1 1) edge1:(2 3) edge2:(2 3) frame1:((1 1) (2 3) 4 5) origin:(1 1) edge1:(2 3) edge2:(4 5) frame1:((1 1) (4 5) 0 0) origin:(1 1) edge1:(4 5) edge2:(0 0) frame1:((1 1) (4 5) 1 1) origin:(1 1) edge1:(4 5) edge2:(1 1) frame1:((1 1) (4 5) 2 3) origin:(1 1) edge1:(4 5) edge2:(2 3) frame1:((1 1) (4 5) 4 5) origin:(1 1) edge1:(4 5) edge2:(4 5) frame1:((2 3) (0 0) 0 0) origin:(2 3) edge1:(0 0) edge2:(0 0) frame1:((2 3) (0 0) 1 1) origin:(2 3) edge1:(0 0) edge2:(1 1) frame1:((2 3) (0 0) 2 3) origin:(2 3) edge1:(0 0) edge2:(2 3) frame1:((2 3) (0 0) 4 5) origin:(2 3) edge1:(0 0) edge2:(4 5) frame1:((2 3) (1 1) 0 0) origin:(2 3) edge1:(1 1) edge2:(0 0) frame1:((2 3) (1 1) 1 1) origin:(2 3) edge1:(1 1) edge2:(1 1) frame1:((2 3) (1 1) 2 3) origin:(2 3) edge1:(1 1) edge2:(2 3) frame1:((2 3) (1 1) 4 5) origin:(2 3) edge1:(1 1) edge2:(4 5) frame1:((2 3) (2 3) 0 0) origin:(2 3) edge1:(2 3) edge2:(0 0) frame1:((2 3) (2 3) 1 1) origin:(2 3) edge1:(2 3) edge2:(1 1) frame1:((2 3) (2 3) 2 3) origin:(2 3) edge1:(2 3) edge2:(2 3) frame1:((2 3) (2 3) 4 5) origin:(2 3) edge1:(2 3) edge2:(4 5) frame1:((2 3) (4 5) 0 0) origin:(2 3) edge1:(4 5) edge2:(0 0) frame1:((2 3) (4 5) 1 1) origin:(2 3) edge1:(4 5) edge2:(1 1) frame1:((2 3) (4 5) 2 3) origin:(2 3) edge1:(4 5) edge2:(2 3) frame1:((2 3) (4 5) 4 5) origin:(2 3) edge1:(4 5) edge2:(4 5) frame1:((4 5) (0 0) 0 0) origin:(4 5) edge1:(0 0) edge2:(0 0) frame1:((4 5) (0 0) 1 1) origin:(4 5) edge1:(0 0) edge2:(1 1) frame1:((4 5) (0 0) 2 3) origin:(4 5) edge1:(0 0) edge2:(2 3) frame1:((4 5) (0 0) 4 5) origin:(4 5) edge1:(0 0) edge2:(4 5) frame1:((4 5) (1 1) 0 0) origin:(4 5) edge1:(1 1) edge2:(0 0) frame1:((4 5) (1 1) 1 1) origin:(4 5) edge1:(1 1) edge2:(1 1) frame1:((4 5) (1 1) 2 3) origin:(4 5) edge1:(1 1) edge2:(2 3) frame1:((4 5) (1 1) 4 5) origin:(4 5) edge1:(1 1) edge2:(4 5) frame1:((4 5) (2 3) 0 0) origin:(4 5) edge1:(2 3) edge2:(0 0) frame1:((4 5) (2 3) 1 1) origin:(4 5) edge1:(2 3) edge2:(1 1) frame1:((4 5) (2 3) 2 3) origin:(4 5) edge1:(2 3) edge2:(2 3) frame1:((4 5) (2 3) 4 5) origin:(4 5) edge1:(2 3) edge2:(4 5) frame1:((4 5) (4 5) 0 0) origin:(4 5) edge1:(4 5) edge2:(0 0) frame1:((4 5) (4 5) 1 1) origin:(4 5) edge1:(4 5) edge2:(1 1) frame1:((4 5) (4 5) 2 3) origin:(4 5) edge1:(4 5) edge2:(2 3) frame1:((4 5) (4 5) 4 5) origin:(4 5) edge1:(4 5) edge2:(4 5) $
0 コメント:
コメントを投稿