CS 421 Homework 9: Filling in Missing Environments - Prof. Samuel N. Kamin, Assignments of Computer Science

Instructions for a homework assignment in a computer science course (cs 421) where students are required to fill in missing environments in an execution sequence of a let expression. The document also includes the evaluation rules and the class notes and supplementary notes for reference.

Typology: Assignments

Pre 2010

Uploaded on 03/16/2009

koofers-user-vfh
koofers-user-vfh 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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, let g b = ... in g c, ρ>
b) Proceed with env. ρ1 = { h <x, let g b = ... in g c, ρ>, • } ρ
2) Evaluate h 4 in ρ1 (application rule):
a) h, ρ1 <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 = { x 4, • } ρ (let rule)
i) fun b -> x+b, ρ2 <b, x+b, ρ2> (function rule)
ii) Evaluate let c = g x in g c in ρ3 = { g <b, x+b, ρ2> , • } ρ2 (let rule)
- Evaluate g x in ρ3 (application rule)
- g, ρ3 <b, x+b, ρ2> (variable rule)
- x, ρ3 4 (variable rule)
- Evaluate x+b in ρ4 = { b 4, • } ρ2 (applic rule, primitive fun, abbreviated)
- x+b, ρ4 8 (variable rule twice, applic of primitive function)
- Evaluate g c in ρ5 = { c 8, • } ρ3 (application rule)
- g, ρ5 <b, x+b, ρ2> (variable rule)
- c, ρ5 8 (variable rule)
- Evaluate x+b in { b 8, • } ρ2
Return 12 (variable rule twice, applic of primitive function)
Name _________________________________________ CS 421, hwk 9 , written part. Due April 3.

Partial preview of the text

Download CS 421 Homework 9: Filling in Missing Environments - Prof. Samuel N. Kamin and more Assignments Computer Science in PDF only on Docsity!

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, let g b = ... in g c, ρ>

b) Proceed with env. ρ1 = { h → <x, let g b = ... in g c, ρ>, • } ρ

  1. Evaluate h 4 in ρ1 (application rule): a) h, ρ 1 ⇓ <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 = { x → 4, • } ρ (let rule) i) fun b -> x+b, ρ 2 ⇓ <b, x+b, ρ2> (function rule)

ii) Evaluate let c = g x in g c in ρ3 = { g → <b, x+b, ρ2> , • } ρ 2 (let rule)

  • Evaluate g x in ρ3 (application rule)
    • g, ρ 3 ⇓ <b, x+b, ρ2> (variable rule)
    • x, ρ 3 ⇓ 4 (variable rule)
    • Evaluate x+b in ρ4 = { b → 4, • } ρ 2 (applic rule, primitive fun, abbreviated)
      • x+b, ρ 4 ⇓ 8 (variable rule twice, applic of primitive function)
  • Evaluate g c in ρ5 = { c → 8, • } ρ 3 (application rule)
    • g, ρ 5 ⇓ <b, x+b, ρ2> (variable rule)
    • c, ρ 5 ⇓ 8 (variable rule)
    • Evaluate x+b in { b → 8, • } ρ 2 Return 12 (variable rule twice, applic of primitive function)

CS 421, hwk 9 , written part. Due April 3. Name _________________________________________