## CSci 1301: Problem Set 5

#### Due: Monday, November 4 at 11:59pm by e-mail

You are required to write signatures and descriptions for all functions, and also descriptions of all your structures. Additionally, functions, except the world problems, must be tested using check-expect. Write your tests before you write a function (but feel free to add more after it's been writen).

The quality of your tests will be graded. Make sure to have enough test cases to demonstrate that the function is correct. I may take points off for a lack of testing (in addition to those taken off for incorrect behavior) if your function doesn't work on particular expected data and there is no test for it. It's much better to leave a test that fails (perhaps in comments) that shows that the function doesn't work on given data and you don't know how to fix it.

### Exercises

1. Write a function `last` that consumes a list and returns its last element. If the list is empty, it gives an error. (4 points)
2. Exercises 148, 149 in Section 11.1 (6 points)
3. Write a function `all-but-last` that consumes a list and returns a list that consists of all elements of the original list except the very last one. If the list is empty, it gives an error. (4 points)
4. Exercises 152, 153 in Section 11.2 (8 points)
5. Write a world program that works the following way: it starts off with a list of squares of the same size and color. Their positions are given as a list of position structures passed to the big bang. Clicking on a square removes it from the world. Your draw function should take the list of position and add them all, recursively, to a scene using `place-image`.
Hint: the state of the world is a list of positions of the centers of squares, so on a click you need return a new list that contains only squares that were not clicked. (15 points)
6. Modify the previous problem so that, additionally, when you click outside of all squares, you are adding a square with the center at the click point (5 points).

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.