6.10.1

#### Lab 8: Practice with Abstraction

Important Note: Whenever you abstract from concrete things, remember to re-define them using the new abstraction. They should have the same signatures and purpose statements as before as well as pass the same tests as before. (Helpers are often useful for eliminating inessential differences among concrete things.) The new abstraction should have its own signature and purpose statement. If the original tests do not provide sufficient coverage for the abstraction, include additional tests.

Exercise 1 Abstract from the following functions:

• Design a function that triples every number in a given list of numbers.

• Design a function that halves every number in a given list of numbers.

Exercise 2 Abstract from init-x-vel and init-y-vel in Assignment 2.

Exercise 3 Abstract from the functions weight and all-balanced? in Assignment 7 (Exercises 7 and 9). Optional: abstract as well from the "helper function that also takes a Mobile as input" in Exercise 8 in Assignment 7.

Note: Although the Intermediate Student Language allows passing functions as inputs to other functions, it doesn’t allow passing and and or as inputs to other functions. To work around this restriction, you may need to define your own helper function which is just a thin wrapper around and.

Exercise 4 Abstract from the following functions:

• Design a function that takes two strings as input and returns the shorter string. (It doesn’t matter which string is returned if they are equally short.)

• Design a function that takes two Posns as input and returns the Posn closer to the origin. (It doesn’t matter which Posn is returned if they are equally close to the origin.)

• Design a function that takes two lists of images and returns the shorter list. (It doesn’t matter which list is returned if they are equally short.)

• Exercise 8 in Assignment 4: "Design a function which, given two addresses, produces the address with the smaller street number." (It doesn’t matter which address is returned if their street numbers are equally small.)

Exercise 5 Do book exercise 239 in How to Design Programs, Second Edition (Draft).

Exercise 6 Abstract from the following functions:

• Design a function draw-pairs like in Exercise 4 of Assignment 5 but using built-in lists.

• (Optional) The "helper function to process the ListOfZombies" in Exercise 10 of Assignment 6.

• Design a function that counts the number of items in a given list of numbers. Do not use the built-in length function.

• Design a function that counts the number of items in a given list of strings. Do not use the built-in length function.

• (Optional) The function count-all-words in Exercise 4 of Assignment 7.

Extra fun: instead of abstracting from these functions, can you define them using the function from class called math or op-lon? How about using the built-in functions foldl or foldr?