Part I: Theoretical Questions
- Is let in L3 a special form? Justify your answer.
- In L3, what is the role of the function valueToLitExp?
- The valueToLitExp function is not needed in the normal evaluation strategy
interpreter (L3-normal.ts). Why?
- The valueToLitExp function is not needed in the environment-model interpreter.
Why?
- What are the reasons that would justify switching from applicative order to normal order
evaluation? Give an example.
- What are the reasons that would justify switching from normal order to applicative order
evaluation? Give an example.
- In general, and as seen in class, substitution requires renaming. However, when the
term that is substituted is “closed” (i.e., it does not contain free variables) then no renaming is required and naive substitution is correct.
- Prove it.
- Write evaluation rules for naive substitution
- Draw an environment diagram for the following computation. Make sure to include the
lexical block markers, the control links and the returned values.
(define a 2) (define goo(lambda (x) (lambda (y)(/ x y)))) (define foo(letrec ((f (goo a))(g (lambda (x) (f x)))) (lambda (x)(if (= x 0) x
(g x))))) (foo (foo 0))
2
Part II: Value Store
In this part, you are given most of the implementation of the programming language L2.1. This language has almost the same syntax as the L2 language taught in class. The main difference is in the choice of evaluation model: it implements the Environment Model (L2 was implemented using the Substitution Model).
You are asked to change the implementation of the environment of L2.1 with two main features:
- 1. Add a set! expression support
- 2. Implement the mutation using a Value Store.
The Value Store
The value store plays the part of the heap in the execution: it is allocated dynamically during the execution and holds the actual value. The environment will now contain only the names of the variables and addresses of the value in the value store. The store is a partial function from these addresses to the values. Mutations occur only at the store. To do that, the value store will be implemented as an array of Box<Value> type.
Impact on the Evaluation
Store API
Functions for managing the store need to be added: makeStore, extendStore, applyStore.
Allocating Memory
The store needs to be extended whenever memory needs to be allocated. You need to figure out where, during the evaluation, this should be done.
Applying Environment
Since the environment holds only pointers to the store, and the actual values reside in the store, the process of fetching the values needs to be changed.
What to do
- β Add set! to the syntax
- β Complete the Store api
- β Think when the store needs to be extended, and modify the code accordingly
- β Pay attention to the global environment and define expressions
- β Pay attention to closures and the environment they hold
- β Make sure all the tests run
ΧΧΧ¦ΧΧ

