Com S 342 --- Principles of Programming Languages EXERCISE 9: DYNAMIC SCOPING (File $Date: 2005/03/23 19:29:01 $) The purpose of this exercise is for you to learn about dynamic binding (also known as dynamic scoping). 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). We expect this to help you think about the readings (see below). If you don't have an answer or an answer that you think is good, write down what you read, and a question or two that would have helped you make progress. Then you can ask that question in class; 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. READINGS: Read exercises 3.30-3.33 on pages 91-92 of "Essentials of Programming Languages" (2nd ed., 2001) by Friedman, Wand, and Haynes. 1. [Understanding dynamic binding/scoping] Do problem 3.33 on page 92 of the text. This problem asks you to give the output of the following code in a version of the defined language that uses dynamic binding (i.e., dynamic scoping). let a = 3 p = proc () %%% draw the picture when execution is here a in let f = proc (a) (p) a = 5 in (f 2) You can print the answer to this on paper. Include a picture or diagram of the run-time stack (growing down the page) at the point where execution reaches the beginning of the body of p, i.e., the line marked with the comment above. 2. [Understanding dynamic binding/scoping] Consider the following expression in the defined language. let y = 342; z = 541 in let f = proc(x) %%% draw the picture when execution is here list(y, +(x, z)); p = proc(y) (f let z = 52 in +(z, 3)) in let y = 5; z = 10 in (p +(y, z)) Using dynamic scoping, (a) draw a picture of the run-time stack when execution reaches the point indicated (with the stack growing up the page), and (b) give the result (if any) of the above expression. (If the expression has no result, or encounters an error, write that.) WHAT TO HAND IN You should have at the beginning of class, your answers to the above questions (or questions and problems you encountered for each part). Make sure your name is on these. Attach the printouts, if any, requested above.