-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswap.bl
44 lines (38 loc) · 1.4 KB
/
swap.bl
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
(common-define swap!
(lambda (n o) ; Num * Num -> Str
(cond ((or (< n 0) (< o 0))
"foobar")
((< n o)
(get-up! n (- o n) '()))
((> n o)
(get-up! o (- n o) '()))
(else "already done"))))
(common-define get-up!
(lambda (n o l) ; Num * Num * List(Pair(REnv, RCont)) -> Str
(if (zero? n)
((delta (e r k)
(got-up! (r 'o) (cons (cons r k) (r 'l)) '())))
((delta (e r k)
(get-up! (sub1 (r 'n)) (r 'o) (cons (cons r k) (r 'l))))))))
(common-define got-up!
(lambda (o l ll) ; Num * List(Pair(REnv, RCont)) * List(Pair(REnv, RCont)) -> Str
(if (zero? o)
(meaning (list 'got-down! (kwote (cons (car ll) (cdr l))) (kwote (cdr ll)))
(caar l)
(cdar l))
((delta (e r k)
(got-up! (sub1 (r 'o)) (r 'l) (cons (cons r k) (r 'll))))))))
(common-define kwote
(lambda (x) ; Val -> RExp
(list 'quote x)))
(common-define got-down!
(lambda (l ll) ; List(Pair(REnv, RCont)) * List(Pair(REnv, RCont)) -> Str
(if (null? ll)
(get-down! l)
(meaning (list 'got-down! (kwote l) (kwote (cdr ll))) (caar ll) (cdar ll)))))
(common-define get-down!
(lambda (l) ; List(Pair(REnv, RCont)) -> Str
(if (null? l)
"done!"
(meaning (list 'get-down! (kwote (cdr l))) (caar l) (cdar l)))))
(load "bye.bl")