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

#### 5.5.3 Vectors

A vector is a fixed-size sequence of Lisp objects, each element may be accessed in constant time—unlike lists where the time taken to access an element is proportional to the position of the element.

The read syntax of a vector is an opening square bracket, followed by zero or more space-separated objects, followed by a closing square bracket. For example,

```[zero one two three]
```

In general it is best to use vectors when the number of elements to be stored is known and lists when the sequence may grow or shrink.

Function: vectorp object

This function returns true if its argument, object, is a vector.

Function: vector #!rest elements

This function creates a new vector containing the arguments given to the function.

```(vector 1 2 3)
⇒ [1 2 3]

(vector)
⇒ []
```
Function: make-vector size #!optional initial-value

Returns a new vector, size elements big. If initial-value is defined each element of the new vector is set to initial-value, otherwise they are all `()`.

```(make-vector 4)
⇒ [() () () ()]

(make-vector 2 t)
⇒ [t t]
```