Com S 342 --- Principles of Programming Languages EXERCISE 03: SYNTAX ABSTRACTION (File $Date: 2004/02/08 22:56:17 $) The purpose of this exercise is for you to learn some basic ideas about flat recursion over lists, with conditionals. As with all exercises, this is to be done individually. And it is due the day this topic is planned to be discussed in class, unless specified otherwise (see the syllabus at: http://www.cs.iastate.edu/~cs342/syllabus.shtml). As with all exercises, you have two choices for doing the work. You can either: - complete it as specified or - write down questions or problems that you had in trying to complete it. If you write down questions or problems you have, these should be detailed enough so that we can tell that you have read the materials and thought about them. (Don't just write: "I didn't understand how to do it". Instead, say what you tried and what you didn't understand.) During the class where this exercise is discussed, you should ask about these difficulties, and clear them up. Don't be shy; there will be other people with the same problem, and everyone can learn by discussing these issues. And you'll most likely see similar things on the homework, so it's best to understand them now. 1. [Advantages of let] Read Section 1.3.2, especially pages 63-66 of the recommended textbook "Structure and Interpretation of Computer Programs", by Abelson and Sussman, which is on reserve and also on-line at the following URL. http://mitpress.mit.edu/sicp/ What advantage does the "let" expression in Scheme give programmers over the use of lambda expressions? That is, why is it convenient to have "let" expressions in Scheme? 2. [Desugaring of let] As described on page 64 of the recommended textbook "Structure and Interpretation of Computer Programs", by Abelson and Sussman, and in the Revised^5 Report on Scheme, the meaning of a let expression of the form (let ((x1 E1) (x2 E2) ... (xn En)) E0) is the same as the expression ((lambda (x1 x2 ... xn) E0) E1 E2 ... En) where x1, x2, ..., xn are variable names, and E0, E1, E2, ..., En are expressions. Using this translation into the application of a lambda, give the equivalent of the following Scheme expressions. That is give an equivalent form that does not use "let". a. (lambda (x) (+ (let ((x 3)) (+ x (* x 10))) x)) b. (lambda (x) (let ((x 3) (y (+ x 2))) (* x y))) WHAT TO HAND IN You should have at the beginning of class, written answers to the above questions (or written out questions and problems you encountered for each part). Make sure your name is on these. Attach the printouts, if any, requested above. ADDITIONAL READINGS If you have time, read section 1.1.6 of the recommended textbook "Structure and Interpretation of Computer Programs", by Abelson and Sussman, which is on reserve and also on-line at the following URL. http://mitpress.mit.edu/sicp/