INFORMATICS 41 • DAVID G. KAY• UC IRVINE • FALL 2011
This assignment is due at the start of lab on Monday, October 17.
(1) In Chapter 22, do exercises 22.5.11, 22.5.12, and 22.6.3, most of which are similar to problems we did in class.
(2) In Chapter 23, do exercise 23.1.3. What kind of operation is this: mapping, filtering, or reducing/folding?
(3) Chapter 24 uses the tools we already have to build something else. As it happens, the "something else" in this case is numbers, which of course are already predefined in the language. That might lead you to ask what the point is of building it ourselves "from scratch." But showing this building process helps you understand how it works and how to build other, more complicated things later. Skim through Chapter 24, but at this point we're not assigning any exercises from that chapter.
(4) The code for the restaurants program we did in class is available at http://www.ics.uci.edu/~kay/scheme/restaurants1.scm. The teachpack for text input and output is at http://www.ics.uci.edu/~kay/scheme/simple-text-io.ss. If you're using your own machine, download and install these files so you can run the restaurants program. (Download the teachpack rather than just copying and pasting its text; to do this, right-click or control-click on the link and then choose to download or save the linked file into the folder where you'll be storing your own code. Then you can add the teachpack via the Language menu in DrScheme: Use "Add Teachpack to the List" to locate the teachpack file; then select it and click OK. Be sure to change the language level to Intermediate Student.) [Technical problems are always possible when installing new software; as always, let us know if things don't work as you think they should.]
Look over the restaurants code to become familiar with how it's organized. The first time you see a few pages of code, it can be daunting, but learning to find your way through a whole program is an important skill and now's the time to start developing it. (Real programs, of course, are hundreds of pages long.) So don't just glance at it and say, "Yeah, whatever." Spend some time studying it. Reading code is an excellent (and under-appreciated) way to build your own programming skills.
Recognize that this code is divided into parts: One part describes individual restaurants and the operations on them; another part describes the collection of restaurants and operations on the collection; that's the most imporant part for our purposes, and the part you should understand thoroughly. Another part (that starts on the first page) controls the whole program, presenting the menu to the user and accepting the commands. In model-view-controller terms, the restaurant and collection parts make up the model, and the first page (plus the get-it function at the end) make up the view and controller. The view/controller parts are less important; you should be able to follow how they work, but we won't be asking you to reproduce code like that without having a reference copy to work from.
Now, try these two tasks. When you modify large, unfamiliar programs, you want to be especially careful (a) to make and test only small changes at one time, (b) to make your changes deliberately, with high confidence that they will work as intended, rather than just changing things haphazardly and hoping they'll work, and (c) make each small set of changes on a new copy of the code, so if you have to "roll back" those changes you won't have far back to go because you'll have a copy of your most recent, stable version. It's easy to lose your way when navigating around a large program; these steps will help keep you on track.
e: Remove (erase) all the restaurants from the collection. If the user types
'p', for example, nothing would be printed. [This will require modifications or additions in a few places. You can do the main part of the work very easily indeed, with a single procedure call. The key is to think functionally, not of changing values but of describing or creating the new value.] Test out your modified program interactively to satisfy yourself that it works as intended.
Based in part on ICS H21 assignments by David G. Kay; modified by David G. Kay for the Informatics Core Course, Fall 2004, Fall 2005, Fall 2008, Fall 2009. Modified by David G. Kay to reflect the Picturing Programs text, Fall 2010. Modified by David G. Kay, Fall 2011.