-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter_4.rkt
78 lines (70 loc) · 1011 Bytes
/
chapter_4.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
74
75
76
77
78
(define add1
(lambda (n)
(+ n 1)
)
)
(define sub1
(lambda (n)
(- n 1)
)
)
(define plus
(lambda (a b)
(cond
((zero? b) a)
(else (add1 (plus a (sub1 b))))
)
)
)
(define minus
(lambda (a b)
(cond
((zero? b) a)
(else (sub1 (minus a (sub1 b))))
)
)
)
(define addtups
(lambda (t1 t2)
(cond
((null? t1) (quote()))
(else
(cons (plus (car t1) (car t2)) (addtup (cdr t1) (cdr t2)))
)
)
)
)
(define mult
(lambda (a b)
(cond
((zero? b) 0)
(else
(plus a (mult a (sub1 b)))
)
)
)
)
(define len
(lambda (lat)
(cond
((null? lat) 0)
(else (add1 (len (cdr lat))))
)
)
)
(define pick
(lambda (n lat)
(cond
((zero? (sub1 n)) (car lat))
(else (pick (sub1 n) (cdr lat)))
)))
(define rempick
(lambda (n lat)
(cond
((zero? n) (cdr lat))
(else
(cons (car lat) (rempick (sub1 n) (cdr lat)))
)
)
)
)