-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20130118Lecture.scm
49 lines (42 loc) · 1.04 KB
/
20130118Lecture.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
(define repeat
(lambda (n a)
(cond
((zero? n) '())
(else (cons a (repeat (- n 1) a))))))
(define cars
(lambda (l)
(cond
((null? l) '())
(else (cons (car (car l)) (cars (cdr l)))))))
(define removeall
(lambda (x l)
(cond
((null? l) '())
((eq? x (car l)) (removeall x (cdr l)))
(else (cons (car l) (removeall x (cdr l)))))))
(define myappend
(lambda (l1 l2)
(cond
((null? l1) l2)
(else (cons (car l1) (myappend (cdr l1) l2))))))
(define replaceall
(lambda (a b l)
(cond
((null? l) '())
((eq? (car l) a) (replaceall a b (cons b (cdr l))))
(else (cons (car l) (replaceall a b (cdr l)))))))
(define squares
(lambda (l)
(cond
((null? l) '())
(else (cons (* (car l) (car l)) (squares (cdr l)))))))
(define myreverse
(lambda (l)
(cond
((null? l) '())
(else (myappend (myreverse (cdr l)) (cons (car l) '()))))))
(define mymap
(lambda (f l)
(cond
((null? l) '())
(else (cons (f (car l)) (mymap f (cdr l)))))))