6.7

Week 2 Set c

home work!

Programming Language BSL

Due Date Fri at 9pm (Week 2)

Purpose This problem set asks you to develop your first complete programs. Follow the design recipe for world programs.

Finger Exercises

Exercise 1 From HtDP 13 or 14. Also solve 18, 19, or 20.

Exercise 2 Design the function render-string, which consumes a number t and produces a text image of the first t letters from the string "qwerty".

Place the text on a white 200 x 100 rectangle. Use black text of font size 22.

Exercise 3 Design the function add-message. Its task is to create an image that represents a sequence of chat messages.

As you can tell, the function consumes three items:
  • a string, which represents the name(s) of the sender of the latest message;

  • another string, which represents the latest message; and

  • an image, which represents what has been said so far and by whom.

The function produces an image that represents the complete history, that is, the history combined with the latest message.

There are no constraints on how you wish to represent messages in an image as long as it clearly expresses who said what.

Here is one possible usage scenario:
(define history-1 empty-image)
(define history-2 (add-message "Matthias and Becca" "hello world" history-1))
(define history-3 (add-message "Ben and Alan" "hello, you guys" history-2))
(define history-4 (add-message "Leena and Nada" "good bye" history-3))
That is, the image argument to add-message is likely to be something that the function produced before, but it doesn’t have to be so.

Graded Exercise

Exercise 4 Design a world program that simulates a type writer for the string "qwerty". The simulation ends when the viewer closes the world canvas.

The main function consumes the initial "time" (in seconds) and counts up from there, one tick per second.

Hint The display shows the first t letters from the string where t is the current time.

Exercise 5 Design a world program that simulates backspacing on a type writer. The simulation ends when the string is erased.

The main function consumes the to-be-erased string.

Constraint The clock must tick once per second. See on-tick.

Hints (1) See stop-when. (2) For each clock tick, one letter disappears from the back of the string.