CS 421 Homework 9: Filling in Missing Environments for Function Execution, Assignments of Computer Science

A homework assignment for a university-level computer science course (cs 421). Students are required to print the document, fill in the missing environments in the given execution sequence for a function definition and expression, and hand it in for evaluation. The evaluation rules in class notes and supplementary notes for march 25.

Typology: Assignments

Pre 2010

Uploaded on 03/11/2009

koofers-user-cst-1
koofers-user-cst-1 🇺🇸

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, 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
3.

Partial preview of the text

Download CS 421 Homework 9: Filling in Missing Environments for Function Execution 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, 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) CS 421, hwk 9 , written part. Due April Name _________________________________________