Está en la página 1de 1

CE133 Lab Settings 5 Student name Student Number Exercise 1.

Take the procedure distance-to-zero from the Presentation 4 and evaluate the following expressions:
1. (distance-to-0 (make-posn 3 4)) 2. (distance-to-0 (make-posn (* 2 3) (* 2 4))) 3. (distance-to-0 (make-posn 12 (- 6 1)))

by hand. Show all steps. Assume that sqr performs its computation in a single step. Check the results with DrScheme's stepper.

Exercise 2. Develop the function clear-bulb. It consumes a symbol that denotes one of the possible colors: 'green, 'yellow, or 'red, and it produces true. Its effect is ``to turn off'' the matching bulb in the traffic light. Specifically, it should clear the disk and display a circle of the matching color instead.

Exercise 3. Develop a function draw-bulb. It consumes a symbol that denotes one of the possible colors: 'green, 'yellow, or 'red, and produces true. Its effect is ``to turn on'' the matching bulb in the traffic light.

Exercise 4. Develop the function switch. It consumes two symbols, each of which stands for a traffic light color, and produces true. Its effects are to clear the bulb for the first color and then to draw the second bulb.

Exercise 5. Develop the function traffic-lights which simulate how the traffic light works. It consumes the current color of a traffic light (as a symbol) and produces the next color that the traffic light shows. That is, if the input is 'green, it produces 'yellow; if it is 'yellow, it produces 'red; and if it is 'red, it produces 'green. Its effect is to switch the traffic light from the input color to the next color.

También podría gustarte