-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsicp_2_1_3.rkt
76 lines (58 loc) · 963 Bytes
/
sicp_2_1_3.rkt
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
65
66
67
68
69
70
71
72
73
#lang scheme
; cons defination
(define (my-cons x y)
(lambda (m)
(cond ((= m 0) x)
((= m 1) y))))
(define (my-car x)
(x 0))
(define (my-cdr x)
(x 1))
; exercise-2.6
(define zero
(lambda (f)
(lambda (x)
x)))
(define (add-1 n)
(lambda (f)
(lambda (x)
(f ((n f) x)))))
(define one
(lambda (f)
(lambda (x)
(f x))))
(define two
(lambda (f)
(lambda (x)
(f (f x)))))
(define (print c)
(display c)
c)
#|(define church-add
(lambda (m)
(lambda (n)
(lambda (f)
(lambda (x)
(m f (n f x)))))))
|#
(define (church-func-call-times x)
(display 'a))
(define (church-add m n)
(lambda (f)
(lambda (x)
((m f) ((n f) x)))))
(define (foo x)
(display 'a))
#|
test case:
> ((two foo) 0)
aa
> (((church-add two one) foo) 0)
aaa
> (((church-add two one) church-func-call-times) 0)
aaa
>
|#
(define (foo1)
(+ 2 3)
100)