入力 | 説明 | デフォ |
---|---|---|
[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?>(と<lists>)を、要素の重複がないように1つのリストに結合。
(<l1?>に足りない要素を継ぎ足していく感じで。)
この関数はその動作をLispのビルトイン関数 union に拠っている。http://www.lispworks.com/documentation/HyperSpec/Body/f_unionc.htm
(<l1?>に足りない要素を継ぎ足していく感じで。)
この関数はその動作をLispのビルトイン関数 union に拠っている。http://www.lispworks.com/documentation/HyperSpec/Body/f_unionc.htm
多重集合(要素の重複を許容した集合)は想定されていない。要素重複の可能性がある場合にはremove-dupをかませて、多重集合は扱わないのが無難。
本来集合は要素の順序に意味がないが、ちょっといじると多少順番を保った出力にできる。
処理系依存らしいが。
処理系依存らしいが。
(defun noRep-union2 (lists oper test key) (let ((the-union (list! (car lists)))) (dolist (one-in (cdr lists)) (setq the-union (nreverse (funcall oper (nreverse the-union) (list! one-in) :test test :key key)))) the-union)) (defmethod* x-union2 ((l1? list) (l2? list) &optional (test 'equal) (key 'identity) &rest lists) :initvals '(nil nil equal identity nil) :indoc '("a list" "a list" "test function" "test key" "more lists") :doc "Merges lists (<l1?> and <l2?> and possibly more) into a single list with no repetitions. <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-union2 '(1 2 3 4 5) '(4 5 6 7 8)) => (1 2 3 4 5 6 7 8)" :icon 191 (noRep-union2 (list* l1? l2? (and lists (list! lists))) 'union test key))
添付ファイル