入力 | 説明 | デフォ |
---|---|---|
[0]<l1?> | リスト1。 | nil |
[1]<l2?> | リスト2。 | nil |
[2 &optional]<test> | 2変数の関数または関数名。テスト用関数。 | equal |
[3 &optional]<key> | 要素に<key>を適用したものを<test>に用いる。 | identity |
[&rest]<lists> | 追加リスト。 | nil (identityになってるのはミスだろう) |
対称差(論理演算で言う排他的論理和のようなもの)。
<l1?>と<l2?>の要素のうち片方だけに含まれるものを1つのリストにして返す。
(<lists>を使って集合を3つ以上にすると、奇数個の集合に属する要素のリストを返す。cf. Wikipedia - 対称差)
この関数はその動作をLispのビルトイン関数 set-exclusive-or に拠っている。http://www.lispworks.com/documentation/HyperSpec/Body/f_set_ex.htm
<l1?>と<l2?>の要素のうち片方だけに含まれるものを1つのリストにして返す。
(<lists>を使って集合を3つ以上にすると、奇数個の集合に属する要素のリストを返す。cf. Wikipedia - 対称差)
この関数はその動作をLispのビルトイン関数 set-exclusive-or に拠っている。http://www.lispworks.com/documentation/HyperSpec/Body/f_set_ex.htm
多重集合(要素の重複を許容した集合)は想定されていない。要素重複の可能性がある場合にはremove-dupをかませて、多重集合は扱わないのが無難。

本来集合は要素の順序に意味がないが、ちょっといじると多少順番を保った出力にできる。
処理系依存らしいが。
処理系依存らしいが。
(defun noRep-xor2 (lists oper test key) (let ((the-union ([[list]]! (car lists)))) (dolist (one-in (cdr lists)) (setq the-union (nreverse ([[funcall]] oper the-union (list! one-in) :test test :key key)))) the-union)) (defmethod* x-Xor2 ((l1? list) (l2? list) &optional (test 'equal) (key 'identity) &rest list) :initvals '(nil nil equal identity nil) :indoc '("a list" "a list" "test function" "test key" "more lists") :doc "XOR's lists (<l1?> and <l2?> and possibly more) into a single list. XOR keeps only the elements present in one list and not in the other one(s). <test> is a function or function name for a binary comparison. <key> is a name or function name to [[apply]] to the elements before comparison. Ex. (x-xor2 '(1 2 3 4 5) '(4 5 6 7 8)) => (1 2 3 6 7 8)" :icon 191 (noRep-xor2 (list* l1? l2? (and list (list! list))) 'set-exclusive-or test key))
添付ファイル