This section describes a number of Common Lisp functions for operating on sequences.
This function returns a given subsequence of the argument sequence, which may be a list, string, or vector. The indices start and end must be in range, and start must be no greater than end. If end is omitted, it defaults to the length of the sequence. The return value is always a copy; it does not share structure with sequence.
As an extension to Common Lisp, start and/or end may be negative, in which case they represent a distance back from the end of the sequence. This is for compatibility with Emacs's
substringfunction. Note that
cl-subseqis the only sequence function that allows negative start and end.
You can use
cl-subseqform to replace a specified range of elements with elements from another sequence. The replacement is done as if by
cl-replace, described below.
This function concatenates the argument sequences together to form a result sequence of type result-type, one of the symbols
list. The arguments are always copied, even in cases such as
(cl-concatenate 'list '(1 2 3))where the result is identical to an argument.
This function fills the elements of the sequence (or the specified part of the sequence) with the value item.
This function copies part of seq2 into part of seq1. The sequence seq1 is not stretched or resized; the amount of data copied is simply the shorter of the source and destination (sub)sequences. The function returns seq1.
If seq1 and seq2 are
eq, then the replacement will work correctly even if the regions indicated by the start and end arguments overlap. However, if seq1 and seq2 are lists that share storage but are not
eq, and the start and end arguments specify overlapping regions, the effect is undefined.
This returns a copy of seq with all elements matching item removed. The result may share storage with or be
eqto seq in some circumstances, but the original seq will not be modified. The
:keyarguments define the matching test that is used; by default, elements
eqlto item are removed. The
:countargument specifies the maximum number of matching elements that can be removed (only the leftmost count matches are removed). The
:endarguments specify a region in seq in which elements will be removed; elements outside that region are not matched or removed. The
:from-endargument, if true, says that elements should be deleted from the end of the sequence rather than the beginning (this matters only if count was also specified).
This deletes all elements of seq that match item. It is a destructive operation. Since Emacs Lisp does not support stretchable strings or vectors, this is the same as
cl-removefor those sequence types. On lists,
cl-removewill copy the list if necessary to preserve the original list, whereas
cl-deletewill splice out parts of the argument list. Compare
nconc, which are analogous non-destructive and destructive list operations in Emacs Lisp.
The predicate-oriented functions
cl-delete-if-not are defined similarly.
This function returns a copy of seq with duplicate elements removed. Specifically, if two elements from the sequence match according to the
:keyarguments, only the rightmost one is retained. If
:from-endis true, the leftmost one is retained instead. If
:endis specified, only elements within that subsequence are examined or removed.
This function deletes duplicate elements from seq. It is a destructive version of
This function returns a copy of seq, with all elements matching old replaced with new. The
:from-endarguments may be used to limit the number of substitutions made.
This is a destructive version of
cl-substitute; it performs the substitution using
asetrather than by returning a changed copy of the sequence.
cl-nsubstitute-if-not are defined
similarly. For these, a predicate is given in place of the