chickadee » slset » slset-union

slset-union LIST_1 ...procedure

Returns the union of the lists.

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 symbols of list B in a left-to-right order. For each symbol that is not a member of A, it is consed onto the front of the result.

In practice, this means the order of the symbols in LIST_1 are kept as-is at the end of the result, but all the LIST_i for I>1 are added in reverse order to the front of the result.

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

(slset-union '(a b c d e) '(a e i o u)) => (u o i a b c d e)

;; Repeated symbols in LIST1 are preserved.
(slset-union '(a a c) '(x a x)) => (x a a c)

;; Trivial cases
(slset-union) => ()
(slset-union '(a b c)) => (a b c)