3 (define (interval n m) ; returns the list (n n+1 n+2 ... m)
4 (if (<= n m) (cons n (interval (+ n 1) m)) '()))
7 (cond ((null? lst) '())
8 ((f (car lst)) (cons (car lst) (keep f (cdr lst))))
9 (else (keep f (cdr lst)))))
11 (define (set-equal? s1 s2)
12 (and (eq? (diff s1 s2) '())
13 (eq? (diff s2 s1) '())))
16 (cond ((null? s1) '())
17 ((memq (car s1) s2) (diff (cdr s1) s2))
18 (else (cons (car s1) (diff (cdr s1) s2)))))
20 (define (intersection s1 s2)
21 (cond ((null? s1) '())
22 ((memq (car s1) s2) (cons (car s1) (intersection (cdr s1) s2)))
23 (else (intersection (cdr s1) s2))))
27 ((memq (car s1) s2) (union (cdr s1) s2))
28 (else (cons (car s1) (union (cdr s1) s2)))))
30 (define (union-multi sets) (foldl union '() sets))
32 (define (foldl f base lst)
35 (foldl f (f base (car lst)) (cdr lst))))
37 (define (pos-in-list x lst)
38 (let loop ((lst lst) (i 0))
39 (cond ((not (pair? lst)) #f)
41 (else (loop (cdr lst) (+ i 1))))))
43 (define (remove x lst)
44 (cond ((null? lst) '())
45 ((eq? x (car lst)) (cdr lst))
47 (remove x (cdr lst))))))
49 (define (replace x y lst)
50 (cond ((null? lst) '())
51 ((eq? x (car lst)) (cons y (cdr lst)))
53 (replace x y (cdr lst))))))
56 (cond ((null? lst) #f)
57 ((null? (cdr lst)) (car lst))
58 (else (last (cdr lst)))))
60 (define (all-but-last lst)
63 (cond ((null? lst) #f)
64 ((null? (cdr lst)) (reverse new))
66 (cons (car lst) new))))))
71 (else (memp p (cdr l)))))