-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_friends.cl
67 lines (61 loc) · 1.07 KB
/
07_friends.cl
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
;; Chapter 7
;; member?
;; checks if an atom is a member of lat
(defun member? (a lat)
(cond
((null lat) nil)
(t(or
(eq (car lat) a)
(member? a (cdr lat))
)
)
)
)
;; multirember
;; removes all occurances of an atom in a lat
(defun multirember (a lat)
(cond
((null lat) '())
((eq a (car lat))
(multirember a (cdr lat)))
(t
(cons (car lat) (multirember a (cdr lat))))
)
)
;; set?
;; checks if a lat is a set
(defun set? (lat)
(cond
((null lat) t)
((member? (car lat) (cdr lat))
nil)
(t
(set? (cdr lat)))
)
)
;; makeset
;; removes duplicates from lat
(defun makeset (lat)
(cond
((null lat) '())
(t
(cons (car lat) (makeset (multirember (car lat) (cdr lat)))))
)
)
;; subset?
;; cheks if set is subset of other set
(defun subset? (set1 set2)
(cond
((null set1) t)
((member? (car set1) set2)
(subset? (cdr set1) set2))
(t nil)
)
)
;; eqset?
;; checks if two sets are equal
(defun eqset? (set1 set2)
(and (subset? set1 set2)
(subset? set2 set1)
)
)