1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SICP読書女子会 2.2.4 (#24~)

Last updated at Posted at 2016-10-19

2.2.4 図形言語


(print "=====2.4 図形言語=====")
(define nil ())


(define (enumerate-interval low high)
    (if 
        (> low high)
        nil
    (cons low (enumerate-interval (+ low 1) high))))

(define (accumulate op initial sequence)
    (if 
        (null? sequence)
        initial
        (op (car sequence) (accumulate op initial (cdr sequence)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define wave
    (accumulate 
        (lambda (i acc) (append acc (list (enumerate-interval 0 15))))
         nil 
        (enumerate-interval 0 15)))




(define wave2 (beside wave (flip-vert wave)))
(define wave4 (below wave2 wave2))

(define (flipped-pairs painter)
(let ((painter2 (beside painter (flip-vert painter))))
(below painter2 painter2)))

(define (right-split painter n)
    (if (= n 0)
        painter
        (let ((smaller (right-split painter (- n 1))))
            (beside painter (below smaller smaller)))))

(define (corner-split painter n)
    (if 
        (= n 0)
        painter
        (let 
            ((up (up-split painter (- n 1)))
            (right (right-split painter (- n 1))))
            (let 
                (
                    (top-left (beside up up))
                    (bottom-right (below right right))
                    (corner (corner-split painter (- n 1)))
                )
                (beside (below painter top-left)
            (below bottom-right corner)))
        )
    )
)

(define (square-limit painter n)
    (let 
        ((quarter (corner-split painter n)))
        (let 
            ((half (beside (flip-horiz quarter) quarter)))
        (below (flip-vert half) half))))

Ex 2.44

(print "===Ex 2.44===")
(define (up-split painter n)
    (if (= n 0)
        painter
        (let ((smaller (up-split painter (- n 1))))
            (below painter (beside smaller smaller)))))

Ex 2.45.....

2.2.4の内容を随時更新していきます。
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?