CIS 352   —   SPRING 2008

Homework 8


Coverage

This homework covers material in Chapter 3 of Essentials of Programming Languages (EOPL).

Logistics

This homework is due in the bin in CST 3-212 by noon on Friday, April 4.

You may work singly or in pairs on this assignment.

N.B. When you are done, please email your code for this homework to Paul () so he can run some tests on it.


EXERCISES

For this assignment, you'll need a copy of the file hw08.scm which is a slight variation on the interpreter 3-7.scm discussed in class.

  1. (30 points) EOPL Exercise 3.40. (You can skip the odd and even stuff at the end.)

    If you look in hw08.scm, you will see a start at solving the problem. In particular,

    Beyond making changes to read-eval-print, you will also need to write a procedure that checks whether a variable already has a binding in the current environment. Try modelling this procedure after apply-env or apply-env-ref.


  2. (30 points) EOPL Exercise 3.43. (Be sure to answer the questions in the text of the exercise.)

    At the very end of hw08.scm there are some sample programs I used in testing my answer to this question. So, for example, evaluating (run tst1) in Scheme will run tst1. Of course, you should add some of your own tests.


  3. (30 points)

    Consider the following expression in our defined language, evaluated in the interpreter's initial environment:
      define x = 5
      define y = 20
      define z = +(x,y)
      let f = proc(w) +(w,+(x,z))
       in 
          let g = proc(y,x) begin set z = +(z,x); (f z) end
              z = 30
           in 
              begin
                set z = +(z,y);
                (g 1 z)
              end
    1. What is the value of this expression if lexical scoping is used? Support your answer by drawing the environments in effect when (g 1 z) is evaluated and (subsequently) when (f x) is evaluated.

    2. Same question as a, but with dynamic scoping this time.



Back to the CIS 352 Homepage
Jim Royer /