chickadee » slset » slset-xor

slset-xor LIST_1 ...procedure

Returns the exclusive-or of the sets. If there are exactly two lists, this is all the symbols that appear in exactly one of the two lists. The operation is associative, and thus extends to the n-ary case -- the symbols that appear in an odd number of the lists. The result may share a common tail with any of the LIST_i parameters.

More precisely, for two lists A and B, A xor B is a list of

  • every symbol of A that does not occur in B
  • every symbol of B that does not occur in A

In the n-ary case, the binary-xor operation is simply folded across the lists.

(slset-xor '(a b c d e) '(a e i o u)) => (d c b i o u)
 
;; For multiple lists, returns symbols that appear in an odd number of lists
(slset-xor '(a b c d e) '(a e i o u) '(b o e) '(x)) => (c d i u e x)

;; Repeated symbols in lists are preserved
(slset-xor '(a b b c d e d) '(a e i o u o)) => (b b c d d i o u o)
(slset-xor '(a b b c d e d) '(a e i o u o) '(x x)) => (b b c d d i o u o x x)

;; Trivial cases.
(slset-xor) => ()
(slset-xor '(a b c d e)) => (a b c d e)