CIS 120 Midterm: CIS 120 UPenn Midterm2 13sp solutions Exam

16 views12 pages

Document Summary

1: reasoning about program behavior (12 points) Multiple choice: for each of the following (well-typed) programs, check the box for the value computed for ans, or mark in nite loop if the program loops. Grading: 4 points each, no partial credit: let x : int = 3 let f (y:int) : int = let x = y + y in x let ans : int = f x ans = (cid:3) 3. 6 (cid:3) 12 (cid:3) in nite loop: let rec f (l:int list) : (int * int) list = begin match l with. | x::xs -> (x,x)::(f l) end let ans : int list = f [1;2] ans = (cid:3) [(0,0)] (cid:3) [(1,1); (2,2); (0,0)] (cid:3) [(0,0); (1,1); (2,2)] In nite loop: let rec f (l: (int -> int) list) : int -> int = begin match l with.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents