-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathoutput.txt
470 lines (334 loc) · 13.9 KB
/
output.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
Matching questions with at least 0.85 in common.
Question 2 on Free Response on cmps112-2015q4-final.tt with accuracy 0.9787234042553191:
\lambda-calculus. Given the expression in the \lambda-calculus
shown at the top of each box, show the derivation order to the
number 25 for each of normal order and applicative order
evaluation. [1pt]
+-----------------------------------------------------------+------------------------------------------------------------+
| normal order evaluation | applicative order evaluation |
+-----------------------------------------------------------+------------------------------------------------------------+
|$ ( lambda x ~ . ~ ~ * ~ x ~ x ) ~ ~ ( + ~ 2 ~ 3 ) ~ ~ = $ | $ ( lambda x ~ . ~ ~ * ~ x ~ x ) ~ ~ ( + ~ 2 ~ 3 ) ~ ~ = $ |
| | |
| | |
| | |
+-----------------------------------------------------------+------------------------------------------------------------+
Question 4 on Multiple Choice part 1 on cmps112-2015q4-final.tt with accuracy 0.9047619047619048:
What is the Ocaml type signature for the definition: let f x =
x;;
(A) val f : 'a -> 'a = <fun>
(B) val f : 'a -> 'b -> 'b * 'a = <fun>
(C) val f : 'a -> 'b -> 'b = <fun>
(D) val f : int -> int = <fun>
Question 3 on Multiple Choice part 1 on cmps112-2015q4-test1.tt with accuracy 0.9411764705882353:
What is type of (+) in Ocaml?
(A) int * int * int
(B) int * int -> int
(C) int -> int * int
(D) int -> int -> int
Question 4 on Multiple Choice part 1 on cmps112-2015q4-test1.tt with accuracy 0.8571428571428571:
What is?
(car (cdr (cons '(1 2 3) '(4 5 6))))
(A) '(1 2 3)
(B) '(4 5 6)
(C) 1
(D) 4
Question 5 on Multiple Choice part 1 on cmps112-2015q4-test1.tt with accuracy 0.875:
In Ocaml, what is the type of [1;2;3;4]?
(A) (list int)
(B) int list
(C) list->int
(D) list<int>
Question 11 on Multiple Choice part 1 on cmps112-2015q4-test2.tt with accuracy 0.9:
The PL/1 language allows a non-local goto directly from a function
to a label in a function deeper down in the function call stack,
thus returning past several levels of function calls. In Java,
something similar can be accomplished by what statement?
(A) goto
(B) implements
(C) synchronized
(D) throw
Question 7 on Multiple Choice part 2 on cmps112-2016q4-final.tt with accuracy 0.9:
The PL/1 language allows a non-local goto directly from a function
to a label in a function deeper down in the function call stack,
thus returning past several levels of function calls. In Java,
something similar can be accomplished by what statement?
(A) goto
(B) implements
(C) synchronized
(D) throw
Question 10 on Multiple Choice part 2 on cmps112-2016q4-final.tt with accuracy 0.9722222222222222:
What is the type of
let f x y z = x + y + z;;
(A) val f : int * int * int -> int
(B) val f : int * int -> int -> int
(C) val f : int -> int * int -> int
(D) val f : int -> int -> int -> int
Question 12 on Multiple Choice part 2 on cmps112-2016q4-final.tt with accuracy 0.9166666666666666:
What is the signature of Ocaml's List.map?
(A) ('a -> 'b) -> 'a list -> 'b list
(B) ('a -> bool) -> 'a list -> 'a list
(C) ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
(D) 'a list -> int
Question 7 on Free Response on cmps112-2016q4-midterm.tt with accuracy 0.8676470588235294:
Ocaml. Define the function zipwith that takes a function and two
lists and returns a new list with the elements combined. Use
failwith if the lists are not of the same length. [2pt]
val zipwith : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
# zipwith (+) [1;2;3;4] [5;6;7;8];;
- : int list = [6; 8; 10; 12]
# zipwith (+) [1;2;3;4] [5;6;7;8;9];;
Exception: Failure "zipwith".
# zipwith (fun a b -> a,b) [1;2;3] ['a';'b';'c'];;
- : (int * char) list = [(1, 'a'); (2, 'b'); (3, 'c')]
# zipwith max [1;2;3;4] [4;3;2;1];;
- : int list = [4; 3; 3; 4]
Question 4 on Multiple Choice part 1 on cmps112-2016q4-midterm.tt with accuracy 0.9642857142857143:
In the expression (lambda (x) (+ x y))
(A) x is bound and y is bound.
(B) x is bound and y is free.
(C) x is free and y is bound.
(D) x is free and y is free.
Question 3 on Multiple Choice part 2 on cmps112-2016q4-midterm.tt with accuracy 0.8888888888888888:
What is the Ocaml type signature of:
(/);;
(A) - : int * int * int
(B) - : int * int -> int
(C) - : int -> int * int
(D) - : int -> int -> int
Question 9 on Multiple Choice part 2 on cmps112-2016q4-midterm.tt with accuracy 1.0:
Given:
# List.map ((+)3) [1;2;3];;
- : int list = [4; 5; 6]
what is the type of List.map ((+)3)?
(A) int -> int
(B) int -> int list
(C) int list -> int
(D) int list -> int list
Question 9 on Free Response on cmps112-2017q2-final.tt with accuracy 0.868421052631579:
Ocaml. Define the functions sum and length by filling in the
blanks. [2pt]
# List.fold_left;;
- : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a = <fun>
# let sum = List.fold_left
________________________________________;;
val sum : int list -> int = <fun>
# sum [1;2;3;4;5];;
- : int = 15
# let length = List.fold_left
________________________________________;;
val length : '_a list -> int = <fun>
# length [1;2;3;4;5];;
- : int = 5
Question 13 on Free Response on cmps112-2017q2-final.tt with accuracy 0.9032258064516129:
Define the function map.
(a) Ocaml. [2pt]
# List.map;;
- : ('a -> 'b) -> 'a list -> 'b list = <fun>
# List.map ((+)6) [1;2;3;4];;
- : int list = [7; 8; 9; 10]
(b) Scheme. [2pt]
> (map (lambda (x) (+ x 6)) '(1 2 3 4))
(7 8 9 10)
Question 7 on Multiple Choice part 1 on cmps112-2017q2-final.tt with accuracy 0.9:
What is (3 4)?
(A) (caar '(1 2 3 4))
(B) (cadr '(1 2 3 4))
(C) (cdar '(1 2 3 4))
(D) (cddr '(1 2 3 4))
Question 11 on Multiple Choice part 1 on cmps112-2017q2-final.tt with accuracy 0.9:
What is 24?
(A) (apply * '(1 2 3 4))
(B) (map * '(1 2 3 4))
(C) (cons * '(1 2 3 4))
(D) (list * '(1 2 3 4))
Question 6 on Multiple Choice part 2 on cmps112-2017q2-final.tt with accuracy 1.0:
Ocaml. List.hd
(A) 'a -> 'a
(B) 'a -> 'a list
(C) 'a list -> 'a
(D) 'a list -> 'a list
Question 2 on Free Response on cmps112-2017q2-midterm.tt with accuracy 0.8709677419354839:
Ocaml. Fill in the blanks: [2pt]
# List.fold_left;;
- : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a = <fun>
# let sum = __________________________________________________
val sum : int list -> int = <fun>
# sum [1;2;3;4;5];;
- : int = 15
# let length = __________________________________________________
val length : '_a list -> int = <fun>
# length [1;2;3;4;5];;
- : int = 5
Question 4 on Free Response on cmps112-2017q2-midterm.tt with accuracy 0.8541666666666666:
Define the function zipwith that takes a function and two lists and
uses the function to join the lists. If the lists are of different
lengths, ignore the excess elements of the longer list. [2pt]
# zipwith;;
- : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list = <fun>
# zipwith (+) [1;2;3] [4;5;6;7];;
- : int list = [5; 7; 9]
Question 1 on Multiple Choice part 1 on cmps112-2017q2-midterm.tt with accuracy 0.9:
Replacing $ (\lambdax~ . ~ + ~ x ~ 1) ~ 2 $ by $ ( + ~ 2 ~ 1 ) $
is an example of
(A) \alpha-reduction
(B) \beta-reduction
(C) \eta-reduction
(D) \lambda-reduction
Question 1 on Multiple Choice part 1 on cmps112-2017q4-final.tt with accuracy 0.9583333333333334:
What is the type of f:
let f (x, y) = x + y;;
(A) f : int * int * int
(B) f : int * int -> int
(C) f : int -> int * int
(D) f : int -> int -> int
Question 2 on Multiple Choice part 1 on cmps112-2017q4-final.tt with accuracy 0.9230769230769231:
What is the type of g:
let g x y = x * y;;
(A) f : int * int * int
(B) f : int * int -> int
(C) f : int -> int * int
(D) f : int -> int -> int
Question 8 on Multiple Choice part 1 on cmps112-2017q4-final.tt with accuracy 0.9166666666666666:
What is (1 2 3 4)
(A) (apply * '(1 2 3 4))
(B) (cons * '(1 2 3 4))
(C) (foldl * '(1 2 3 4))
(D) (map * '(1 2 3 4))
Question 5 on Multiple Choice part 2 on cmps112-2017q4-final.tt with accuracy 0.875:
PL/I's non-local goto (unwinding the function call stack several
levels) can be evaluated in C++ and Java using:
(A) break
(B) continue
(C) return
(D) throw
Question 2 on Free Response on cmps112-2017q4-midterm.tt with accuracy 0.9:
Scheme. Write a function to reverse a list. [3pt]
> (reverse '(1 2 3 4 5))
(5 4 3 2 1)
> (reverse '())
()
Question 3 on Free Response on cmps112-2017q4-midterm.tt with accuracy 0.9117647058823529:
Scheme. Define map. [2pt]
> (map (lambda (x) (+ 5 x)) '(1 2 3 4))
(6 7 8 9)
> (map (lambda (x) (cons 5 x)) '(1 2 3 4))
((5 . 1) (5 . 2) (5 . 3) (5 . 4))
Question 7 on Multiple Choice part 1 on cmps112-2017q4-midterm.tt with accuracy 0.9:
What is 10?
(A) (apply + '(1 2 3 4))
(B) (cons + '(1 2 3 4))
(C) (filter + '(1 2 3 4))
(D) (foldl + '(1 2 3 4))
Question 10 on Multiple Choice part 1 on cmps112-2017q4-midterm.tt with accuracy 0.9285714285714286:
Type of (+)?
(A) int * int * int
(B) int * int -> int
(C) int -> int * int
(D) int -> int -> int
Question 11 on Multiple Choice part 1 on cmps112-2017q4-midterm.tt with accuracy 0.9:
What is (3 4)?
(A) (caar '(1 2 3 4))
(B) (cadr '(1 2 3 4))
(C) (cdar '(1 2 3 4))
(D) (cddr '(1 2 3 4))
Question 12 on Multiple Choice part 1 on cmps112-2017q4-midterm.tt with accuracy 0.9545454545454546:
In the expression $ ( \lambda x . ( + x ) y ) $
(A) $x$ is bound and $y$ is bound.
(B) $x$ is bound and $y$ is free.
(C) $x$ is free and $y$ is bound.
(D) $x$ is free and $y$ is free.
+---------------------------------+
| |
| |
| |
| |
| |
| |
| |
|jpgs/math-but-yesterday-you-said.ps
| |
| |
| |
| |
| |
| |
| |
+---------------------------------+
Question 3 on Multiple Choice part 1 on cmps112-2018q1-final.tt with accuracy 1.0:
# sqrt;;
(A) - : float * float = <fun>
(B) - : float -> float = <fun>
(C) - : int * int = <fun>
(D) - : int -> int = <fun>
Question 4 on Multiple Choice part 1 on cmps112-2018q1-final.tt with accuracy 1.0:
10
(A) (apply '+ '(1 2 3 4))
(B) (apply '+ (1 2 3 4))
(C) (apply + '(1 2 3 4))
(D) (apply + (1 2 3 4))
Question 5 on Multiple Choice part 1 on cmps112-2018q1-final.tt with accuracy 1.0:
# (<) 2;;
(A) - : 'a -> bool = <fun>
(B) - : bool -> 'a = <fun>
(C) - : bool -> int = <fun>
(D) - : int -> bool = <fun>
Question 1 on Free Response on cmps112-2018q1-midterm.tt with accuracy 0.8709677419354839:
Without using any higher-order functions, code the function re-
verse, which will reverse a list.
(a) Scheme. [2pt]
> (reverse '(1 2 3 4))
(4 3 2 1)
(b) Ocaml. [2pt]
# reverse [1;2;3;4];;
- : int list = [4; 3; 2; 1]
Question 3 on Free Response on cmps112-2018q1-midterm.tt with accuracy 0.8780487804878049:
Without using any higher-order functions, code the function fold_
left, which will take a function, a unit, and a list, and fold the
list.
(a) Scheme. [2pt]
> (fold_left + 0 '(1 2 3))
6
(b) Ocaml. [2pt]
# fold_left;;
- : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a = <fun>
# fold_left (+) 0 [1;2;3];;
- : int = 6
Question 4 on Free Response on cmps112-2018q1-midterm.tt with accuracy 0.896551724137931:
Without using any higher-order functions, code the function find,
which will return a value associated with a given key. Indicate
not found as shown here. Use the sample interactions to figure out
the structure and arguments to this function.
(a) Ocaml. [3pt]
# find;;
- : ('a -> 'b -> bool) -> 'a -> ('b * 'c) list -> 'c option =
<fun>
# find (=) 3 [(1,2);(3,4);(5,6)];;
- : int option = Some 4
# find (=) 3 [(5,6);(7,8)];;
- : int option = None
(b) Scheme. Use cond and not if. Return #f if not found. [3pt]
> (find = 3 '((1 2) (3 4) (5 6)))
4
> (find = 3 '((5 6) (7 8)))
#f
Question 2 on Multiple Choice part 2 on cmps112-2018q1-midterm.tt with accuracy 0.9:
What will print:
5
(A) ((lambda (a b) (+ a b)) '(2 3))
(B) ((lambda (a b) (+ a b)) 2 3)
(C) (lambda (a b) (+ a b)) (2 3)
(D) (lambda (a b) (+ a b)) 2 3
Question 3 on Multiple Choice part 2 on cmps112-2018q1-midterm.tt with accuracy 0.9230769230769231:
Output of:
# (-);;
(A) - : int * int * int = <fun>
(B) - : int * int -> int = <fun>
(C) - : int -> int * int = <fun>
(D) - : int -> int -> int = <fun>
Question 5 on Multiple Choice part 2 on cmps112-2018q1-midterm.tt with accuracy 0.9090909090909091:
What will print:
(1 2 7)
(A) '(1 2 ,(+ 3 4))
(B) ,(1 2 `(+ 3 4))
(C) `(1 2 '(+ 3 4))
(D) `(1 2 ,(+ 3 4))