A sequence is an ordered collection of elements, implemented as either a vector or a list.
Sequences can be created by the function make-sequence, as well as other functions that create objects of types that are subtypes of sequence (e.g., list, make-list, mapcar, and vector).
A sequence function is a function defined by this specification or added as an extension by the implementation that operates on one or more sequences. 14.0.0 19Whenever a sequence function must construct and return a new vector, it always returns a simple vector. Similarly, any strings constructed will be simple strings.
Figure 17–1. Standardized Sequence Functions
When an object is being considered iteratively against each element of a sequence by an operator listed in the next figure, it is sometimes useful to control the way in which the presence of is tested in is tested by . This control is offered on the basis of a function designated with either a :test or :test-not argument.
!!! Sandra wonders if this table is complete.
Figure 17–2. Operators that have Two-Argument Tests to be Satisfied
The object might not be compared directly to . If a :key argument is provided, it is a designator for a function of one argument to be called with each as an argument, and yielding an object to be used for comparison. (If there is no :key argument, is .)
Added per Barmar. -kmp 16-Feb-92The function designated by the :key argument is never called on itself. However, if the function operates on multiple sequences (e.g., as happens in set-difference), will be the result of calling the :key function on an element of the other sequence.
A :test argument, if supplied to , is a designator for a function of two arguments, and . An is said (or, sometimes, an and an are said) to satisfy the test if this :test function returns a generalized boolean representing true.
A :test-not argument, if supplied to , is designator for a function of two arguments, and . An is said (or, sometimes, an and an are said) to satisfy the test if this :test-not function returns a generalized boolean representing false.
If neither a :test nor a :test-not argument is supplied, it is as if a :test argument of #'eql was supplied.
The consequences are unspecified if both a :test and a :test-not argument are supplied in the same call to .
(remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'equal)
→ (foo bar "BAR" "foo" "bar")
(remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'equalp)
→ (foo bar "BAR" "bar")
(remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'string-equal)
→ (bar "BAR" "bar")
(remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'string=)
→ (BAR "BAR" "foo" "bar")
(remove 1 '(1 1.0 #C(1.0 0.0) 2 2.0 #C(2.0 0.0)) :test-not #'eql)
→ (1)
(remove 1 '(1 1.0 #C(1.0 0.0) 2 2.0 #C(2.0 0.0)) :test-not #'=)
→ (1 1.0 #C(1.0 0.0))
(remove 1 '(1 1.0 #C(1.0 0.0) 2 2.0 #C(2.0 0.0)) :test (complement #'=))
→ (1 1.0 #C(1.0 0.0))
(count 1 '((one 1) (uno 1) (two 2) (dos 2)) :key #'cadr) → 2
(count 2.0 '(1 2 3) :test #'eql :key #'float) → 1
(count "FOO" (list (make-pathname :name "FOO" :type "X")
(make-pathname :name "FOO" :type "Y"))
:key #'pathname-name
:test #'equal)
→ 2
When using one of the functions in the next figure, the elements of a sequence are filtered not on the basis of the presence or absence of an object under a two argument predicate, as with the functions described in Section 17.2.1 (Satisfying a Two-Argument Test), but rather on the basis of a one argument predicate.
!!! KMP wonders if this table is complete.
Figure 17–3. Operators that have One-Argument Tests to be Satisfied
The element might not be considered directly. If a :key argument is provided, it is a designator for a function of one argument to be called with each as an argument, and yielding an object to be used for comparison. (If there is no :key argument, is .)
Functions defined in this specification and having a name that ends in “-if” accept a first argument that is a designator for a function of one argument, . An is said to satisfy the test if this :test function returns a generalized boolean representing true.
Functions defined in this specification and having a name that ends in “-if-not” accept a first argument that is a designator for a function of one argument, . An is said to satisfy the test if this :test function returns a generalized boolean representing false.
(count-if #'zerop '(1 #C(0.0 0.0) 0 0.0d0 0.0s0 3)) → 4
(remove-if-not #'symbolp '(0 1 2 3 4 5 6 7 8 9 A B C D E F))
→ (A B C D E F)
(remove-if (complement #'symbolp) '(0 1 2 3 4 5 6 7 8 9 A B C D E F))
→ (A B C D E F)
(count-if #'zerop '("foo" "" "bar" "" "" "baz" "quux") :key #'length)
→ 3
sequence System Classcopy-seq Functionelt Accessorfill Functionmake-sequence Functionsubseq Accessormap Functionmap-into Functionreduce Functioncount, count-if, count-if-not Functionlength Functionreverse, nreverse Functionsort, stable-sort Functionfind, find-if, find-if-not Functionposition, position-if, position-if-not Functionsearch Functionmismatch Functionreplace Functionsubstitute, substitute-if, substitute-if-not, nsubstitute, nsubstitute-if, nsubstitute-if-not Functionconcatenate Functionmerge Functionremove, remove-if, remove-if-not, delete, delete-if, delete-if-not Functionremove-duplicates, delete-duplicates Function