Com S 342 --- Principles of Programming Languages EXERCISE 12: LOCAL BINDING (File $Date: 2004/03/31 04:12:16 $) The purpose of this exercise is for you to learn about local binding in the interepreters in chapter 3 of EOPL. 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. [local binding in the interpreter] Read sections 3.3-3.4 of "Essentials of Programming Languages" (2nd ed., 2001) by Friedman, Wand, and Haynes. In the code for eval-expression in figure 3.6 on page 83, the let-exp clause reads (let-exp (ids rands body) (let ((args (eval-rands rands env))) (eval-expression body (extend-env ids args env)))) a. Why is the call to eval-rands correct here? b. Could the code for the let-exp case be written without using Scheme's let expression? If so, write that, and if not, explain why not. c. Using two or more experiments, show that the interpreter gives the correct lexical scoping rules to the defined language. 2. [Changes to the interpreter] a. What would happen if the code for the let-exp case were as follows instead? (let-exp (ids rands body) (eval-expression body (extend-env ids rands env))) b. Is it possible to change the interpreter so that it does sequential binding, like Scheme's let* construct? For example, so that let x = 5 y = +(x,1) in *(y, y) returns 36? If so describe how to make this change. 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 THOUGHTS If you have time, try to implement the sequential binding semantics of part 2b above.