Description
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.
2