Exercises
Exercise 5.1. [*]
Develop the function allergic. The function consumes a
Request (see exercise 1.3 and produces the list of
strings that are associated with false in the Request.
Compare allergic with toppings (also see
exercise 1.3). Abstract the two functions into a single
function.
Optional: Can you use the new function to extract all positive numbers from a list of numbers? If not, can you create a common abstraction?
Exercise 5.2. [challenging!] Compare these two functions:
;; | ;; |
Exercise 5.3.
Develop the function blink. It consumes a natural number n
and a position and draws and clears a blinking rectangle at that position
n times.
| Add the
teachpack draw.ss |
Hint 1: Use sleep-for-a-while.
Hint 2: Develop two auxiliary functions: one for drawing an object and one for clearing it.
Design a common abstraction for the two auxiliary functions. Then change the function so that it draws/clears a “lunar lander.” Approximate the lander with one small rectangle atop a large rectangle and two short, rectangular legs sticking out from the large rectangle.
Exercise 5.4.
Design all-numbers. The function determines whether all
items in a list (of arbitrary values) are numbers.
Develop the function all-symbols, which determines whether all
items in a list are symbols.
Abstract the two functions into a single function. Use the new function to define a function that determines whether all numbers on a list of numbers are positive.
Exercise 5.5. [*] Compare the following two data definitions:
;; A | ;; A |
Exercise 5.6.
Use every to define numbers-to-strings from
exercise 1.2.