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)
50 (remove x (cdr lst))))))