chickadee » srfi-1 » lset-union

lset-union = list_1 ...procedure

Returns the union of the lists, using = for the element-equality procedure.

The union of lists A and B is constructed as follows:

  • If A is the empty list, the answer is B (or a copy of B).
  • Otherwise, the result is initialised to be list A (or a copy of A).
  • Proceed through the elements of list B in a left-to-right order. If B is such an element of B, compare every element R of the current result list to B: (= R B). If all comparisons fail, B is consed onto the front of the result.

However, there is no guarantee that = will be applied to every pair of arguments from A and B. In particular, if A is eq? to B, the operation may immediately terminate.

In the n-ary case, the two-argument list-union operation is simply folded across the argument lists.

(lset-union eq? '(a b c d e) '(a e i o u)) => 
    (u o i a b c d e)
 
;; Repeated elements in LIST1 are preserved.
(lset-union eq? '(a a c) '(x a x)) => (x a a c)
 
;; Trivial cases
(lset-union eq?) => ()
(lset-union eq? '(a b c)) => (a b c)