Next: Filtering Lists, Previous: Selecting List Components, Up: Lists [Contents][Index]
take
returns the first i elements of list x.
drop
returns all but the first i elements of list x.
(take '(a b c d e) 2) => (a b) (drop '(a b c d e) 2) => (c d e)
x may be any value—a proper, circular, or dotted list:
(take '(1 2 3 . d) 2) => (1 2) (drop '(1 2 3 . d) 2) => (3 . d) (take '(1 2 3 . d) 3) => (1 2 3) (drop '(1 2 3 . d) 3) => d
For a legal i, take
and drop
partition the list in
a manner which can be inverted with append
:
(append (take x i) (drop x i)) = x
drop
is exactly equivalent to performing i cdr
operations on x; the returned value shares a common tail with
x. If the argument is a list of non-zero length, take
is
guaranteed to return a freshly-allocated list, even in the case where
the entire list is taken, e.g. (take lis (length lis))
.
Equivalent to take
and drop
, respectively.
list-head
is deprecated and should not be used.
list-tail
is defined by R7RS.
Start and end must be exact integers satisfying
0 <= start <= end <= (length list)
sublist
returns a newly allocated list formed from the elements
of list beginning at index start (inclusive) and ending at
end (exclusive).
Returns a list consisting of the elements of the first list followed by the elements of the other lists.
(append '(x) '(y)) ⇒ (x y) (append '(a) '(b c d)) ⇒ (a b c d) (append '(a (b)) '((c))) ⇒ (a (b) (c)) (append) ⇒ ()
The resulting list is always newly allocated, except that it shares structure with the last list argument. The last argument may actually be any object; an improper list results if the last argument is not a proper list.
(append '(a b) '(c . d)) ⇒ (a b c . d) (append '() 'a) ⇒ a
Returns a list that is the argument lists concatenated together.
The arguments are changed rather than copied. (Compare this with
append
, which copies arguments rather than destroying them.) For
example:
(define x (list 'a 'b 'c)) (define y (list 'd 'e 'f)) (define z (list 'g 'h)) (append! x y z) ⇒ (a b c d e f g h) x ⇒ (a b c d e f g h) y ⇒ (d e f g h) z ⇒ (g h)
Next: Filtering Lists, Previous: Selecting List Components, Up: Lists [Contents][Index]