
Please print these two pages, fill in the answers, and hand in the homework in class.
The evaluation rules are given in the class notes and supplementary notes for March 25. In the
following execution sequence, fill in the missing environments. You should use the linked
version of environments, as was done in the second part of the class notes and in the
supplementary notes. In some cases, weโve given names to the environments; in subsequent
execution steps, you can refer to those environments by name instead of writing the entire
environment.
The execution sequence is given for the following top-level definition and expression:
let h x = let g b= x+b
in let c = g x
in g c;;
h 4;;
Execution starts in environment ฯ.
1) Evaluate definition of h (top-level let rule):
a) fun x -> let g b = ... in g c, ฯ ๏ <x, x, let g b = ... in g c, ฯ>
b) Proceed with env. ฯ1 = __________________________________________
2) Evaluate h 4 in ฯ1 (application rule):
a) h, ฯ1 ๏ <x, x, let g b = ... in g c, ฯ> (variable rule)
b) 4, ฯ1 ๏ 4 (constant rule)
c) Evaluate let g b = ... in g c in ฯ2 = _______________________________ (let rule)
i) fun b -> x+b, ฯ2 ๏ <x, b, x+b, ฯ2> (function rule)
ii) Evaluate let c = g x in g c in ฯ3 = _________________________________ (let rule)
- Evaluate g x in ฯ3 (application rule)
- g, ฯ3 ๏ <x, b, x+b, ฯ2> (variable rule)
- x, ฯ3 ๏ 4 (variable rule)
- Evaluate x+b in ฯ4 = __________________ (applic rule, prim. fun, abbreviated)
- x+b, ฯ4 ๏ 8 (variable rule twice, applic of primitive function)
- Evaluate g c in ฯ5 = ___________________________ (application rule)
- g, ฯ5 ๏ <x, b, x+b, ฯ2> (variable rule)
- c, ฯ5 ๏ 8 (variable rule)
- Evaluate x+b in _____________________________
Return 12 (variable rule twice, applic of primitive function)
Name _________________________________________CS 421, hwk 9 , written part. Due April