2014年4月15日火曜日

開発環境

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

その他参考書籍

問題 2.49.

コード(BBEdit, Emacs)

sample.rkt

;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-advanced-reader.ss" "lang")((modname sample) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ())))
(require (planet soegaard/sicp:2:1/sicp))

;; a
;; 見やすいように、フレームより0.1だけ内側に設定
(define painter-outline
  (segments->painter
   (list (make-segment (make-vect 0.1 0.1)
                       (make-vect 0.1 0.9))
         (make-segment (make-vect 0.1 0.9)
                       (make-vect 0.9 0.9))
         (make-segment (make-vect 0.9 0.9)
                       (make-vect 0.9 0.1))
         (make-segment (make-vect 0.9 0.1)
                       (make-vect 0.1 0.1)))))

(paint painter-outline)

;; b
(define painter-x
  (segments->painter
   (list (make-segment (make-vect 0.1 0.1)
                       (make-vect 0.9 0.9))
         (make-segment (make-vect 0.1 0.9)
                       (make-vect 0.9 0.1)))))

(paint painter-x)

;; c
(define painter-diamond
  (segments->painter
   (list (make-segment (make-vect 0.1 0.5)
                       (make-vect 0.5 0.9))
         (make-segment (make-vect 0.5 0.9)
                       (make-vect 0.9 0.5))
         (make-segment (make-vect 0.9 0.5)
                       (make-vect 0.5 0.1))
         (make-segment (make-vect 0.5 0.1)
                       (make-vect 0.1 0.5)))))

(paint painter-diamond)

入出力結果(生成された画像)

0 コメント:

コメントを投稿