Starting from:
$30

$24

Paradigms of Programming Open Book Test

Q1 [4; Week 9] Determine and explain (both needed to fetch points) the outputs of the programs P1, P2, P3 and P4 that use continuations:

; P1

(+ 4 (call/cc (lambda (cont) 13)))

; P2

(+ 4 (call/cc (lambda (cont) (cont 10) 13)))

; P3

(define foo #f)

(+ 4 (call/cc (lambda (cont) (set! foo cont) 13)))

    • P4 (in sequence with P3) (foo 100)
(foo 416)



Q2 [5; Week 3] For the following  bonacci function:

F =  f: n: if (< n 2) n (+ (f (    n 1)) (f (    n 2)))

show that ((Y F ) n) correctly computes bonacci(n), where Y is the Y-combinator. You can use backslashes (‘\’) to depict lambdas, unless you are using LATEX.

 
Q3 [6; Week 13] Say we de ne an ADT in Haskell to construct lists by adding elements to the end (instead of front):
 



Q4 [4; Week 12] Recall that A4 su ered from order-independence of pure logic, thus resulting into imprecise results with respect to the control- ow of the input programs. For example, the object o1 in the following code escaped (along with o2):

 
Discuss how would you approach the problem to impart ow-sensitivity. As an instance, we want to be able to identify that only o2 escapes in the program that would have generated the above facts. (This question doesn’t ask you to write the whole Prolog solution.)


 










2

More products