[Index of Problem Sets]

Problem Set 04—Notes and link to solution

This problem set had to do with how to update a world program when the changing information changes in a significant way -- so much so that the world state type has to be replaced. In this case that change had a typical structure - the world state type in the first version was included by reference in the second version. In problem set 3 the world state type was Ball, in problem set 4 it was ListOfBall. You will see this kind of change again in problem set 5. (Simpler changes are possible, sometimes all you have to do is make a small change to the world state type, like add a field.)

When something like this happens a good rule of thumb is to first do no harm. You already have a lot of functions that operate on Ball. Start by not harming them. Add a bunch of blank lines or something to the file before them to put them aside where you can come back to them. Then work through the recipe systematically.

Once you have your new ListOfBall data definition you can update the @htdw tag. Then you can update the main function. It changes a lot because the world state type has changed. So all the signatures change and the name of the handlers change. You will have to make wish list entries for the new handlers.

Then you can start designing those handlers. As part of doing that you will need some helpers, and here's where all those functions that operate on Ball come in handy. next-ball you can use unchanged. render-ball is similar but not the same as place-ball.

As always, the key thing is to work systematically and let the recipes guide you. And don't throw out something that works unless you have finished the whole program and you know you don't need it.

The solution for this problem set is: