-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20130218Lecture.scm
69 lines (59 loc) · 1.34 KB
/
20130218Lecture.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
65
66
67
68
69
; apply: takes a function and a list and applies the function to the list
; (apply + '(1 2 3)) ==> 6
(define myapply
(lambda (f l)
(cond
((null? l) '())
((null? (cdr l)) (car l))
(else (f (car l) (myapply f (cdr l)))))))
;sum: takes a list and sums the values in the list
;(define sum
; (lambda (l)
; (myapply + l)))
(define apply-f
(lambda (f)
(lambda (l)
(myapply f l))))
;We can redifine sum to be (define sum (apply-f +))
(define factoial-accum
(lambda (n total)
(if (zero? n)
total
(factorial-accum (- n 1) (* total n)))))
(define factorial-cps
(lambda (n k)
(if (zero? n)
(k 1)
(factorial-cps (- n 1) (lambda (v) (k (* v n)))))))
(define len
(lambda (l)
(if (null? l)
0
(+ l (len (cdr l))))))
(define len-cps
(lambda (l k)
(if
(define member?
(lambda (a l)
(cond
((null? l) #f)
((eq? a (car l)) #t)
(else (member? a (cdr l))))))
(define member-cps?
(lambda (a l k)
(cond
((null? l) (k #f))
((eq? a (car l)) (k #t))
(else (member-cps? a (cdr l) k)))))
(define set?
(lambda (l)
(cond
((null? l) #t)
((member? (car l) (cdr l)) #f)
(else (set? (cdr l))))))
;Is not corrent right now
(define set-cps?
(lambda (l k)
(cond
((null? l) (k #t))
(else (set-cps?