remove-duplicates, delete-duplicates
remove-duplicates sequence &key from-end test test-not start end key → result-sequence
delete-duplicates sequence &key from-end test test-not start end key → result-sequence
sequence—a proper sequence.
from-end—a generalized boolean. The default is false.
test—a designator for a function of two arguments that returns a generalized boolean.
test-not—a designator for a function of two arguments that returns a generalized boolean.
start, end—bounding index designators of sequence. The defaults for start and end are 0 and nil, respectively.
key—a designator for a function of one argument, or nil.
result-sequence—a sequence.
remove-duplicates returns a modified copy of sequence from which any element that matches another element occurring in sequence has been removed.
Moon's suggested interpretation follows:
If sequence is a vector, the result is a vector that has the same actual array element type as sequence. Moved to notes per Schulenburg #1 (by X3J13 vote at May 4-5, 1994 meeting). -kmp 9-May-94 The result might or might not be simple, and might or might not be \term{identical} to \param{sequence}. Another possible interpretation: The result might or might not be \term{identical} to \param{sequence}. If the result is a \term{vector} that is not \term{identical} to \param{sequence}, the result is a \term{fresh} \term{simple array} of \term{rank} one.If sequence is a list, the result is a list. End Moon's suggested interpretation.
delete-duplicates is like remove-duplicates, but delete-duplicates may modify sequence.
14.3.0 13The elements of sequence are compared pairwise, and if any two match, then the one occurring earlier in sequence is discarded, unless from-end is true, in which case the one later in sequence is discarded.
remove-duplicates and delete-duplicates return a sequence of the same type as sequence with enough elements removed so that no two of the remaining elements match. The order of the elements remaining in the result is the same as the order in which they appear in sequence.
remove-duplicates returns a sequence 14.3.0 14that may share with sequence or may be identical to sequence if no elements need to be removed.
delete-duplicates, when sequence is a list, is permitted to setf any part, car or cdr, of the top-level list structure in that sequence. When sequence is a vector, delete-duplicates is permitted to change the dimensions of the vector and to slide its elements into new positions without permuting them to produce the resulting vector.
14.3.0 16
(remove-duplicates "aBcDAbCd" :test #'char-equal :from-end t) → "aBcD"
(remove-duplicates '(a b c b d d e)) → (A C B D E)
(remove-duplicates '(a b c b d d e) :from-end t) → (A B C D E)
(remove-duplicates '((foo #\a) (bar #\%) (baz #\A))
:test #'char-equal :key #'cadr) → ((BAR #\%) (BAZ #\A))
(remove-duplicates '((foo #\a) (bar #\%) (baz #\A))
:test #'char-equal :key #'cadr :from-end t) → ((FOO #\a) (BAR #\%))
(setq tester (list 0 1 2 3 4 5 6))
(delete-duplicates tester :key #'oddp :start 1 :end 6) → (0 4 5 6)
14.3.0 15delete-duplicates might destructively modify sequence.
None.
Should signal an error of type type-error if sequence is not a proper sequence.
Section 3.2.1 (Compiler Terminology), Section 3.6 (Traversal Rules and Side Effects)
Moved from Description per Schulenburg #1 (by X3J13 vote at May 4-5, 1994 meeting). -kmp 9-May-94If sequence is a vector, the result might or might not be simple, and might or might not be identical to sequence.
The :test-not argument is deprecated.
14.3.0 17These functions are useful for converting sequence into a canonical form suitable for representing a set.