GNU Emacs Lisp Reference Manual
In Emacs Lisp, a sequence is either a list, a vector or a string. The common property that all sequences have is that each is an ordered collection of elements. This section describes functions that accept any kind of sequence.
t if object is a list, vector, or
string, nil otherwise.
Storing a new element into the copy does not affect the original
sequence, and vice versa. However, the elements of the new
sequence are not copies; they are identical (eq) to the elements
of the original. Therefore, changes made within these elements, as
found via the copied sequence, are also visible in the original
sequence.
If the sequence is a string with text properties, the property list in the copy is itself a copy, not shared with the original's property list. However, the actual values of the properties are shared. See Text Properties.
See also append in Building Lists, concat in
Creating Strings, and vconcat in Vectors, for others
ways to copy sequences.
(setq bar '(1 2))
=> (1 2)
(setq x (vector 'foo bar))
=> [foo (1 2)]
(setq y (copy-sequence x))
=> [foo (1 2)]
(eq x y)
=> nil
(equal x y)
=> t
(eq (elt x 1) (elt y 1))
=> t
;; Replacing an element of one sequence.
(aset x 0 'quux)
x => [quux (1 2)]
y => [foo (1 2)]
;; Modifying the inside of a shared element.
(setcar (aref x 1) 69)
x => [quux (69 2)]
y => [foo (69 2)]
nil), a wrong-type-argument error is signaled.
(length '(1 2 3))
=> 3
(length ())
=> 0
(length "foobar")
=> 6
(length [1 2 3])
=> 3
nil;
otherwise, they trigger an args-out-of-range error.
(elt [1 2 3 4] 2)
=> 3
(elt '(1 2 3 4) 2)
=> 3
(char-to-string (elt "1234" 2))
=> "3"
(elt [1 2 3 4] 4)
error-->Args out of range: [1 2 3 4], 4
(elt [1 2 3 4] -1)
error-->Args out of range: [1 2 3 4], -1
This function generalizes aref (see Array Functions) and
nth (see List Elements).