# hw1-sol - HW 1 Evaluation and Environments CS 421 Fall 2007...

This preview shows pages 1–3. Sign up to view the full content.

HW 1 – Evaluation and Environments CS 421 – Fall 2007 Revision 1.0 Assigned September 4, 2007 Due September 11, 2007, 2:00pm, in class Extension 48 hours (20% penalty) 1 Change Log 1.0 Initial Release. 2 Turn-In Procedure Your answers to the following questions are to be hand-written, or printed, neatly on one or more sheets of paper, each with your name in the upper right corner. The homework is to be turned in in class at the start of class. Alternately, you may hand it to Prof. Elsa Gunter in person before the deadline. 3 Objectives and Background The purpose of this HW is to test your understanding of the order of evaluation of expressions in OCaml; the scope of variables, and the state of environments used during evaluation Another purpose of HWs is to provide you with experience answering non-programming written questions of the kind you may experience on the midterms and ﬁnal. 4 Problems 1. (15 pts) Below is a fragment of OCaml code, with various program points indicated by numbers with comments. let x = 3.9;; let y = 17;; ( * 1 * ) let z = let x = 4 in ( * 2 * ) x + y;; ( * 3 * ) let f x y = x + y + z;; ( * 4 * ) let g w = f w w;; let z = g z;; ( * 5 * ) 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
For each of program points 1, 2, 3, 4 and 5, please describe the environment in effect after evaluation has reached that point. You may assume that the evaluation begins in an empty environment, and that the environment is cumu- lative thereafter. The program points are supposed to indicate points at which all complete preceding declarations have been fully evaluated. In describing the environments 1 through 4, you may use set notation, as done in class, or you may use the update operator + . If you use set notation, no duplicate bindings should occur. The answer for program point 5 should be written out fully in set notation. Solution: ρ 1 = { y 17 , x 3 . 9 } ρ 2 = { x 4 } + ρ 1 = { x 4 , y 17 } ρ 3 = { z 21 } + ρ 1 = { z 21 , y 17 , x 3 . 9 } ρ 4 = { f → h x 7→ fun y -> x + y + z , ρ 3 i} + ρ 3 = { f → h x 7→ fun y -> x + y + z , ρ 3 i , z 21 , y 17 , x 3 } • { z 63 , g → h w 7→ f w w , ρ 4 i , f → h x 7→ fun y -> x + y + z , ρ 3 i , y 17 , x 3 } = { z 63 , g → h w 7→ f w w , { f → h x 7→ fun y -> x + y + z , { z 21 , y 17 , x 3 . 9 }i , z 21 , y 17 , x 3 }i , f → h x 7→ fun y -> x + y + z , { z 21
This is the end of the preview. Sign up to access the rest of the document.

## This homework help was uploaded on 04/21/2008 for the course CS 421 taught by Professor Kamin during the Fall '08 term at University of Illinois at Urbana–Champaign.

### Page1 / 5

hw1-sol - HW 1 Evaluation and Environments CS 421 Fall 2007...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online