# Function VECTOR-PUSH, VECTOR-PUSH-EXTEND

### Syntax

• vector-push new-element vectornew-index-p
• vector-push-extend new-element vector `&optional` extensionnew-index

### Description

vector-push and vector-push-extend store new-element in vector. vector-push attempts to store new-element in the element of vector designated by the fill pointer, and to increase the fill pointer by one. If the `(>= (fill-pointer vector) (array-dimension vector 0))`, neither vector nor its fill pointer are affected. Otherwise, the store and increment take place and vector-push returns the former value of the fill pointer which is one less than the one it leaves in vector.

vector-push-extend is just like vector-push except that if the fill pointer gets too large, vector is extended using adjust-array so that it can contain more elements. extension is the minimum number of elements to be added to vector if it must be extended.

vector-push and vector-push-extend return the index of new-element in vector. If `(>= (fill-pointer vector) (array-dimension vector 0))`, vector-push returns nil.

### Examples

```
(defparameter *fable* (list 'fable))

→
*FABLE*

(defparameter *fa*
(make-array 8 :fill-pointer 2
:initial-element 'first-one))

→
*FA*

(vector-push *fable* *fa*)

→
2

(fill-pointer fa)

→
3

(eq (aref fa 2) fable)

→
true

(defparameter *array*
(make-array 5 :element-type 'character
:adjustable t
:fill-pointer 3))

→
*ARRAY*

(vector-push-extend #\X *array*)

→
3

(fill-pointer *array*)

→
4

(vector-push-extend #\Y *array* 4)

→
4

(array-total-size *array*)

→
→ 5 ;(or more)

(vector-push-extend #\Z *array* 4)

→
5

(array-total-size *array*)

→
→ 9 ;(or more)

```

### Affected By

The value of the fill pointer.

How vector was created.

### Exceptional Situations

An error of type error is signaled by vector-push-extend if it tries to extend vector and vector is not actually adjustable.

An error of type error is signaled if vector does not have a fill pointer.

None.