Next: lists misc, Previous: lists compar, Up: lists [Index]
Synonyms for car
, cadr
, caddr
, ...
(third '(a b c d e)) ⇒ c
The fundamental pair deconstructor:
(lambda (p) (values (car p) (cdr p)))
take-left
returns the first i elements of list
dotted. drop-left
returns all but the first i
elements of list dotted.
(take-left '(a b c d e) 2) ⇒ (a b) (drop-left '(a b c d e) 2) ⇒ (c d e)
dotted may be any value: a proper, circular, or dotted list:
(take-left '(1 2 3 . d) 2) ⇒ (1 2) (drop-left '(1 2 3 . d) 2) ⇒ (3 . d) (take-left '(1 2 3 . d) 3) ⇒ (1 2 3) (drop-left '(1 2 3 . d) 3) ⇒ d
For a legal i, take-left
and drop-left
partition the
list in a manner which can be inverted with append:
(append (take-left x i) (drop-left x i)) = x
drop-left
is exactly equivalent to performing i cdr
operations on dotted; the returned value shares a common tail with
dotted.
If the argument is a list of non–zero length, take-left
is
guaranteed to return a freshly–allocated list, even in the case where
the entire list is taken: (take-left dotted (length+ dotted))
.
take-right
returns the last i elements of dotted.
drop-right
returns all but the last i elements of
dotted.
(take-right '(a b c d e) 2) ⇒ (d e) (drop-right '(a b c d e) 2) ⇒ (a b c)
The returned list may share a common tail with the argument list.
dotted may be any finite list, either proper or dotted:
(take-right '(1 2 3 . d) 2) ⇒ (2 3 . d) (drop-right '(1 2 3 . d) 2) ⇒ (1) (take-right '(1 2 3 . d) 0) ⇒ d (drop-right '(1 2 3 . d) 0) ⇒ (1 2 3)
For a legal i, take-right
and drop-right
partition
the list in a manner which can be inverted with append:
(append (drop-right flist i) (take-right flist i)) = flist
The return value of take-right
is guaranteed to share a common
tail with dotted.
If the argument is a list of non–zero length, drop-right
is
guaranteed to return a freshly–allocated list, even in the case where
nothing is dropped, e.g. (drop-right dotted 0)
.
take!
and drop-right!
are like take
and
drop-right
, but they are allowed to alter the argument list to
produce the result.
An error is raised if the length of the list is less than i.
split-at
splits the list dotted at index i, returning
a list of the first i elements, and the remaining tail. It is
equivalent to:
(values (take-left x i) (drop-left x i))
split-at!
is allowed to alter the argument list to produce the
result.
(split-at '(a b c d e f g h) 3) ⇒ (a b c) (d e f g h)
last
returns the last element of the non–empty, finite list
pair. last-pair
returns the last pair in the non–empty,
finite list pair.
(last '(a b c)) ⇒ c (last-pair '(a b c)) ⇒ (c)
Next: lists misc, Previous: lists compar, Up: lists [Index]