Previous: , Up: Sequences   [Contents][Index]

5.5.6 Sequence Functions

Function: sequencep arg

Returns true if arg is a sequence, i.e. a list or an array.

Function: length sequence

This function returns the length (an integer) of the sequence sequence.

(length "abc")
    ⇒ 3

(length '(1 2 3 4))
    ⇒ 4

(length [x y])
    ⇒ 2

For utf-8 encoded strings, use utf8-string-length (see utf-8).

Function: copy-sequence sequence

Returns a new copy of the sequence sequence. Where possible (in lists and vectors) only the ‘structure’ of the sequence is newly allocated: the same objects are used for the elements in both sequences.

(copy-sequence "xy")
    ⇒ "xy"

(setq x '("one" "two"))
    ⇒ ("one" "two")
(setq y (copy-sequence x))
    ⇒ ("one" "two")
(eq x y)
    ⇒ ()
(eq (car x) (car y))
    ⇒ t
Function: elt sequence position

This function returns the element of sequence position elements from the beginning of the sequence.

This function is a combination of the nth and aref functions.

(elt [0 1 2 3] 1)
    ⇒ 1

(elt '(foo bar) 0)
    ⇒ foo