INFORMATICS 41 • DAVID G. KAY • UC IRVINE • FALL 2011

**Second Homework **

This assignment is due at the start of lab on Monday, October 3; show your completed work to the TA. We have already covered most of this material in class. If you don't quite finish this by Monday's lab, try to finish by Wednesday; you need to develop these skills.

**(1) **Re-read Chapter 6, remembering that we won't expect you to memorize the details of creating animations. Then read Chapters 7–18. That sounds like a lot, but some of it we've already seen and most of it is pretty straightforward. Let us know, as always, if you have questions.

**(2)** In Chapter 7, do exercises 7.1.2, 7.1.3, 7.1.5, 7.3.1, 7.6.2 (just for one of the operations), 7.7.2, and 7.7.14. Note that the `build3-image`

function described in section 7.8.2 takes two numbers and three functions as its arguments. This is an example of treating functions as first-class objects, which we will return to later. It shouldn't seem that odd to have a function that takes and uses other functions: Think of a robotic arm in an auto factory. We can put a screwdriver attachment on the end of the arm and the arm will tighten screws; then we can put a spray-painting attachment on the end of the arm and it will paint something. The robotic arm is a machine (a function) that takes as its parameter another machine (the screwdriver or painting attachment) and uses that parameter machine to do some task.

**(3)** In Chapter 8, do exercise 8.4.2. In Chapter 9, do exercise 9.2.2. In Chapter 10, do exercise 10.2.1.

**(4)** In Chapter 11, the extended example in section 11.2 uses inexact numbers in a very unusual way, to indicate real-world measurements that aren't precise. It's true that real-world measurements can be imprecise, but that's not what inexact numbers in Scheme are intended for. For our purposes, it is perfectly fine to use normal numbers like 28 for the miles per gallon and to forget about inexact numbers. (What inexact numbers in Scheme *are* intended for is situations where a decimal representation, like .33333, doesn't exactly equal the exact number 1/3. Using inexact numbers in repeated computations can accumulate those small errors into something significant; this is often called **roundoff error**. Scheme lets us represent rational numbers as actual ratios, or fractions—1/3 is a perfectly legal Scheme number—and that saves us from worrying about imprecise representations. However, we sometimes do need to convert our numeric results into a decimal representation, rounding off as necessary, and Scheme lets us do that with the function `exact->inexact`

. So long as a programmer uses that at the end of the computations, he or she can avoid significant inaccuracy.)

Do exercises 11.2.2 (replacing all the inexact numbers, too) and 11.5.2 (which gives you valuable practice finding your way around a slightly larger program; note that you can get all the code at once from the textbook's web site).

**(5) **In Chapter 13, do exercises 13.2.4, 13.3.3, and 13.7.3. In Chapter 14, do exercises 14.1.2 and 14.2.2. In Chapter 15, do exercises 15.3.1, 15.32, and 15.5.1.

**(6) **Look at the sections D, E, F, G, I, and J (except J7 and J8) of the Scheme Finger Exercises. You don't have to write the answers down or turn them in, but make sure you know how to do them.

Written by David G. Kay to reflect *Picturing Programs* by Stephen Bloch, Fall 2010; revised Fall 2011.

David G. Kay, kay@uci.edu

Friday, September 30, 2011 8:37 AM