-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex-4.21.scm
65 lines (58 loc) · 1.33 KB
/
ex-4.21.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
52
53
54
55
56
57
58
59
60
61
62
63
64
; a
(define (fib n)
(cond ((= n 0) 0)
((= n 1) 1)
(else (+ (fib (- n 1))
(fib (- n 2))))))
; (fib 5)
((lambda (n)
((lambda (fib)
(fib fib n))
(lambda (fb k)
(cond ((= k 0) 0)
((= k 1) 1)
(else (+ (fb fb (- k 1))
(fb fb (- k 2))))))))
5)
; b
(define (f1 x)
(define (even? n)
(if (= n 0)
#t
(odd? (- n 1))))
(define (odd? n)
(if (= n 0)
#f
(even? (- n 1))))
(even? x))
(define (f2 x)
((lambda (even? odd?)
(even? even? odd? x))
(lambda (ev? od? n)
(if (= n 0) #t (od? ev? od? (- n 1))))
(lambda (ev? od? n)
(if (= n 0) #f (ev? ev? od? (- n 1))))))
(define (main args)
; (print ((lambda (n)
; ((lambda (fact)
; (fact fact n))
; (lambda (ft k)
; (if (= k 1)
; 1
; (* k (ft ft (- k 1)))))))
; 10))
; (print (fib 8))
; (print ((lambda (n)
; ((lambda (fib)
; (fib fib n))
; (lambda (fb k)
; (cond ((= k 0) 0)
; ((= k 1) 1)
; (else (+ (fb fb (- k 1))
; (fb fb (- k 2))))))))
; 8))
(print (f1 8))
(print (f1 7))
(print (f2 8))
(print (f2 7))
)