Chapter 2, Building Abstractions with Data

Section - 2.2 - Hierarchical Data and the Closure Property

Exercise 2.51


Note that I am using transform-painter from the sicp package of Dr Racket. Its arguments are slightly different from the transform-painter code given in the book.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(define (below painter1 painter2)
  (let ((split-point (make-vect 0.0 0.5)))
    (let ((paint-bot
                   ( (transform-painter 
                          (make-vect 0.0 0.0)
                          (make-vect 1.0 0.0)
                          split-point
                     )
                     painter1
                   )
          )
          (paint-up
                   ( (transform-painter
                          split-point
                          (make-vect 1.0 0.5)
                          (make-vect 0.0 1.0)
                     )
                     painter2
                   )
          )
         ) 
         (lambda (frame)
            (paint-bot frame)
            (paint-up frame)
         )
      )
   )
)

Alternative implementation of below using ‘beside` and rotations:

1
2
3
(define (below-alt painter1 painter2)
        (rotate90 (beside (rotate270 painter1) (rotate270 painter2)))
)