Next: , Previous: , Up: lists   [Index]

### 23.6 Selectors

Function: first pair
Function: second pair
Function: third pair
Function: fourth pair
Function: fifth pair
Function: sixth pair
Function: seventh pair
Function: eighth pair
Function: ninth pair
Function: tenth pair
Syntax: fifth/stx pair
Syntax: sixth/stx pair
Syntax: seventh/stx pair
Syntax: eighth/stx pair
Syntax: ninth/stx pair
Syntax: tenth/stx pair

Synonyms for `car`, `cadr`, `caddr`, ...

```(third '(a b c d e))
⇒ c
```
Function: car+cdr pair

The fundamental pair deconstructor:

```(lambda (p)
(values (car p) (cdr p)))
```
Function: take-left dotted i
Function: drop-left dotted i
Syntax: take-left/stx dotted i
Syntax: drop-left/stx dotted i

`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))`.

Function: take-right dotted i
Function: drop-right dotted i
Syntax: take-right/stx dotted i
Syntax: drop-right/stx dotted i

`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)`.

Function: take-left! dotted i
Function: drop-right! dotted i
Syntax: take-left!/stx dotted i
Syntax: drop-right!/stx dotted i

`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.

Function: split-at dotted i
Function: split-at! dotted i
Syntax: split-at/stx dotted i
Syntax: split-at!/stx dotted 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)
```
Function: last pair
Function: last-pair pair
Syntax: last/stx pair
Syntax: last-pair/stx pair

`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: , Previous: , Up: lists   [Index]