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.
(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,
define construct is already added as
a new sort of program: a-defn, with
fields id and exp.
read-eval-print code as been modified
so that every time you fire
up read-eval-print, it creates a fresh
initial environment (called cur-env). The
code you add should use
cur-env, not init-env.
You should delete the indicated line (a placeholder so that hw08.scm will load) and replace it with your code.
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.
(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.
(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
What is the value of this expression if (g 1 z) is evaluated
and (subsequently) when (f x) is evaluated.
Same question as a, but with