-
Notifications
You must be signed in to change notification settings - Fork 2
/
chapter07.scm
51 lines (40 loc) · 890 Bytes
/
chapter07.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
; The Little Schemer Chapter 7 Exercises
(load "common.scm")
(define set?
(lambda (lat)
(cond
((null? lat) #t)
((member? (car lat) (cdr lat)) #f)
(else (set? (cdr lat))))))
(define makeset
(lambda (lat)
(cond
((null? lat) '())
(else
(cons (car lat) (makeset (multirember (car lat) (cdr lat))))))))
(define subset?
(lambda (set1 set2)
(cond
((null?set1) #t)
(else (and (member? (car set1) set2) (subset? (cdr set1) set2))))))
(define eqset?
(lambda (set1 set2)
(and (subset? set1 set2) (subset? set2 set1 ))))
; Pairs
(define first
(lambda (p)
(car p)))
(define second
(lambda (p)
(car (cdr p))))
(define build
(lambda (s1 s2)
(cons s1
(cons s2
'()))))
(define third
(lambda (l)
(car (cdr (cdr l)))))
(define fun?
(lambda (rel)
(set? (firsts rel))))