-
Notifications
You must be signed in to change notification settings - Fork 6
/
cps-sol.scm
34 lines (31 loc) · 920 Bytes
/
cps-sol.scm
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
(define foo1
(lambda (x k)
(let ((thunk (lambda () (modulo x 2))))
(if (= x 0)
(thunk)
(foo1 (- x 1) (lambda (b)
(if b
(thunk)
(foo1 (- x 2)))))))))
(foo1 10 (lambda (v) v))
(define foo2
(lambda (f k)
(k (lambda (xs k)
(if (null? xs)
(k xs)
(foo2 f (lambda (p1)
(foo2 f (lambda (p2)
(p2 (cdr xs) (lambda (v)
(p1 v k))))))))))))
(foo2 add1 (lambda (p) (p '(1 2 3) (lambda (v) v))))
(define foo3
(lambda (f n k)
(f n (lambda (a)
(f a k)))))
(foo3 (lambda (x k) (k (add1 x))) 0 (lambda (v) v))
(define foo4
(lambda (f k)
(f (lambda (g k) (g g k))
(lambda (g k) (g g k))
k)))
(foo4 (lambda (a b k) (k a)) (lambda (v) v))