Com S 342 --- Principles of Programming Languages HOMEWORK 3: TOOL-MAKERS (File $Date: 1999/10/06 03:55:23 $) Due: problems 1-4, at beginning of class October 7, 1999. In this homework you will learn about how one can build tool-makers using procedures that return procedures. The section headings below give the readings related to the problems. WHAT TO HAND IN For code hand in *both* your printout of the code and a transcript of testing. Be sure the code has your name and section information in a comment at the top as described in homework 0 at the top. Although you may want to write your code out by hand as practice for taking the tests, and then type it in, please don't turn in handwritten code, unless the problem specifically states otherwise. *No* credit will be given for programming problems unless you also hand in a transcript that includes test output. For many problems, we will provide test harnesses; for such problems you must run our tests. For some problems, you will have to provide your own tests. For this homework, the directory $PUB/homework/hw3.tst contains test harnesses for the coding problem. For problems that don't require code, you can write the answer by hand. or you can hand in a printout. SICP section 1.3 1. [cubic] a. (15 points) Do exercise 1.40 in Scheme. Call your procedure cubic. You can test your code using (test-hw3 "cubic") from within scheme342. Be sure to hand in a printout of your testing. (See homework 1 for details of how to do this). b. (15 points) Also do this exercise in Java. In your Java code, use a public class Cubic that implements the interface DoubleFun that is in the course library (in the file $PUB/lib/DoubFun.java). You should *not* copy the files in the course library. However, to test your code, copy our test harness file $PUB/homework/hw3.tst/CubicTest.java to your directory, compile it, and then make a script of this test. Be sure to hand in a printout of your testing. (See homework 1 for more detailed directions.) 2. [double] (10 points) Do exercise 1.41 in Scheme. You can test your code using (test-hw3 "double"). from within scheme342. Be sure to hand in a printout of your testing. Also, don't forget to answer the question at the end of the exercise. 3. [repeated] (25 points) Do exercise 1.43 in the book in Scheme. Note that ((repeated f 0) x) should return the value of x. You can assume that the second argument to repeated is a nonnegative integer. You can test your code using (test-hw3 "repeated"). from within scheme342. Be sure to hand in a printout of your testing. 4. [smoothing] a. (30 points) Using Java, do the first 5 lines of exercise 1.44 in the book, using 0.001 for the value of dx. That is, you should write a public class Smooth which implements the Java interface DoubleFun from the course library. You should *not* copy the files in the course library. However, to test your code, copy our test harness file $PUB/homework/hw3.tst/SmoothTest.java to your directory, compile it, and then make a script of this test. Be sure to hand in a printout of your testing. b. (10 points) Consider the part of exercise 1.44 in the book that talks about repeated smoothing of a function. You do not have to implement this, but instead answer the following questions. (i) If you wrote a class Repeated in Java that implemented the interface DoubleFun, would that allow you to repeatedly apply smoothing to a function? Explain. (Think about the types involved.) (ii) Would the Scheme version of repeated function be able to repeatedly apply smoothing? Explain. 5. (extra credit) If you have done all of the above, you can do extra credit in SICP section 1.3 by selecting any of the problems not listed above that are found in that section. These problems will be worth 15 points extra credit if done in Scheme, and 20 if done in Java. Be sure to hand in both your code and test output. Extra credit problems should be handed in separately from the other problems.