-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathex2.45-abstract-split.scm
52 lines (40 loc) · 1.07 KB
/
ex2.45-abstract-split.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(define painter (list 0))
(define (below a b)(append (list b) (list a)))
(define (beside a b) (append a b))
(define (right-split1 painter n)
(if (= n 0)
painter
(let ((smaller (right-split1 painter (- n 1))))
(beside painter (below smaller smaller)))))
(define (up-split1 painter n)
(if (= n 0)
painter
(let ((smaller (up-split1 painter (- n 1))))
(below painter (beside smaller smaller)))))
(define (split o1 o2)
(lambda (painter n)
(define (iter n)
(if (= n 0)
painter
(let ((smaller (iter (- n 1))))
(o1 painter (o2 smaller smaller)))))
(iter n)))
;; this is stupid
(define (split1 o1 o2)
(lambda (painter n)
(if (= n 0)
painter
(let ((smaller ((split1 o1 o2) painter (- n 1))))
(o1 painter (o2 smaller smaller))))
))
(define (split2 o1 o2)
(define (anon painter n)
(if (= n 0)
painter
(let ((smaller (anon painter (- n 1))))
(o1 painter (o2 smaller smaller)))))
anon
)
(define right-split (split2 beside below))
(right-split painter 2)
; (define up-split (split below beside))