Union of Sets

(union x y ) returns a list containing the elements that occur in either x or y.


(define (union x y)
  (if (pair? x)
      (if (memv (car x) y)
          (union (cdr x) y)
          (cons (car x) (union (cdr x) y)))
      y))

> (union '(c a t) '(b a g)) (c t b a g)

Contents    Page-10    Prev    Next    Page+10    Index