CS 1110 Final: CS 1110 Cornell 2013 Fall Final Exams2012 Fall Final Exam answers
CS312 Fall 2001
Prelim 1
October 18, 2001
Name
Instructions
Write your name on the line above. There are seven questions on 10 num-
bered pages. Check now that you have all the pages. Write your answers in
the boxes provided. Ambiguous answers will be considered incorrect. The
exam is closed book except for the handouts provided. Do not begin until
instructed. You have 90 minutes. Good luck!
1234567
a
/14 /12 /7 /8 /7 /10 /9 /67
1
1. (14 points) Evaluate each of the following ML expressions and say what
value will be produced. Note: One of the expressions is erroneous. For
the erroneous expression, say approximately what error message will be
produced.
(a) let
val x = 4
val x = x + 1
val x = 1 - x
in
x * x
end
16
(b) (fn x => fn y => y - x) 2 3
1
(c) let
val s:string = "xyzzy"
val c:char = #"c"
val x:int * int = String.size s * Char.ord c
in
~x
end
Type mismatch in declaration of x
(d) let
fun shuffle (x:int list) (y:int list) : int list =
case x of
nil => y
| u::z => u::(shuffle y z)
in
shuffle [1,2,3] [4,5]
end
[1,4,2,5,3]
2
(e) let
val x = 3
val y = 4
val y =
let val x = 5
in x + y
end
in
x + y
end
12
(f) foldl (op ^) "2" (map Int.toString [1,3])
"312"
(g) let
val imp = String.implode
val chr = List.map Char.chr
val inc = List.map (fn x => x + 1)
val ord = List.map Char.ord
val exp = String.explode
in
(imp o chr o inc o ord o exp) "Mississippi"
end
"Njttjttjqqj"
3