乐正

Actions speak louder than words.

Sicp-ex2-51

问题

定义对画家的below操作,它以两个画家为参数。在给定了一个框架后,由below得到的 画家要求将第一个画家在框架下面画图,要求第二个画家在框架的上部画图。请按两种方式 定义below:首先写一个类似于上面beside过程;另一个直接通过beside和适当的旋 转操作(来自练习2.50)完成有关工作。

解答

练习2.51 (ex2-51.scm) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(define (below painter1 painter2)
  (let ((split-point (make-vect 0 0.5)))
    (let ((paint-top
            (transform-painter painter2
                               split-point
                               (make-vect 1.0 0)
                               (make-vect 0 1.0)))
          ((paint-bottom
             (transform-painter painter1
                                (make-vect 0 0)
                                (make-vect 1.0 0)
                                split-point))))
      (lambda (frame)
        (paint-top frame)
        (paint-bottom frame)))))

(define (below2 painter1 painter2)
  (beside (rotate90 painter1)
          (rotate270 painter2)))

draft

« sicp-ex2-50 sicp-ex2-52 »

Comments