#

    ;; Produces the union of two sets
    (define (set-union set1 set2)
      (let loop ((set1 set1)
    	     (set2 set2))
        (if (null? set2)
    	set1
    	(let ((item (car set2)))
    	  (if (member item set1)
    	      (loop set1 (cdr set2))
    	      (loop (cons item set1) (cdr set2)))))))

    (define (all? pred coll)
      (if (null? coll)
          #t
          (and (pred (car coll))
               (all? pred (cdr coll)))))

    (define (filter pred coll)
      (let loop ((ret '())
                 (coll coll))
        (if (null? coll)
            (reverse ret)
            (let ((a (car coll)))
              (if (pred a)
                  (loop (cons a ret) (cdr coll))
                  (loop ret (cdr coll)))))))

Last modified: Wed Jan 25 22:04:37 CET 2012