SICP Exercise 2.51 below 1

Exercise 2.51.  Define the below operation for painters. Below takes two painters as arguments. The resulting painter, given a frame, draws with the first painter in the bottom of the frame and with the second painter in the top. Define below in two different ways -- first by writing a procedure that is analogous to the beside procedure given above, and again in terms of beside and suitable rotation operations (from exercise 2.50).

SOLUTION


The code and tests are here.

Note: The implementation of the procedure segments->painter in the textbook is different from the similarly named procedure in the sicp plt package.

The plt package procedure takes a list of segments and draws them. Moreover, this procedure draws segments only inside the unit square where 0 <= x,y <= 1. Any points ouside the unit square are simply ignored (at least, there is no visual output).

The textbook implementation also takes a list of segments but instead of drawing them directly, evaluates to a procedure that takes a frame as its input. This procedure when supplied with a frame, maps all the segments from the originally supplied list to this frame and then draws them. Now, the 'draw-line' procedure in the textbook implementation has no equivalent in the plt package. So in order to use the plt package implementation of segments->painter, I have modified the textbook implementation of segments->painter.

Finally, to prevent a name-clash, I have renamed the textbook procedure by appending a '-local' suffix.



Comments

Popular posts from this blog

SICP Exercise 2.56 differentiation rule

SICP Exercise 1.28 (Miller-Rabin Test)

SICP Exercise 4.18 a alternative strategy for interpreting internal definitions