Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

vector

List of symbols:

make-vec, vec, vec->list, vec-clear!, vec-insert!, vec-pop!, vec-push!, vec-remove!, vec-slice

make-vec

Usage: (make-vec capacity default)

Namespace: root

Make a new vector with capacity and default item(s).

Example:

(test::assert-equal [] (make-vec))
(test::assert-equal ['x 'x 'x] (make-vec 3 'x))
(test::assert-equal [nil nil nil nil nil] (make-vec 5 nil))
(test::assert-equal [] (make-vec 5))

vec

Usage: (vec item1 item2 .. itemN)

Namespace: root

Make a new vector with items.

Example:

(test::assert-equal [] (vec))
(test::assert-equal [1 2 3] (vec 1 2 3))

vec->list

Usage: (vec->list vector)

Namespace: root

Convert a vector to a list.

No Examples

vec-clear!

Usage: (vec-clear! vector)

Namespace: root

Clear all elements from a vector. This is a destructive form!

Example:

(def test-vec [1 2 3])
(test::assert-false (empty? test-vec))
(vec-clear! test-vec)
(test::assert-true (empty? test-vec))
(test::assert-equal [] test-vec)

vec-insert!

Usage: (vec-insert! vector index new-element) -> vector

Namespace: root

Inserts new-element at index and moves following elements right in vector. This is destructive!

Example:

(def test-insert-nth-vec [1 2 3])
(test::assert-equal [1 2 3] test-insert-nth-vec)
(vec-insert! test-insert-nth-vec 1 5)
(test::assert-equal [1 5 2 3] test-insert-nth-vec)
(vec-insert! test-insert-nth-vec 2 6)
(test::assert-equal [1 5 6 2 3] test-insert-nth-vec)
(vec-insert! test-insert-nth-vec 0 4)
(test::assert-equal [4 1 5 6 2 3] test-insert-nth-vec)

vec-pop!

Usage: (vec-pop! vector) -> object

Namespace: root

Pops the last object off of the end of the vector. This is destructive!

Example:

(def test-pop-vec (vec 1 2 3))
(test::assert-equal 3 (vec-pop! test-pop-vec))
(test::assert-equal [1 2] test-pop-vec)
(test::assert-equal 2 (vec-pop! test-pop-vec))
(test::assert-equal [1] test-pop-vec)
(test::assert-equal 1 (vec-pop! test-pop-vec))
(test::assert-equal [] test-pop-vec)

vec-push!

Usage: (vec-push! vector object) -> vector

Namespace: root

Pushes the provided object onto the end of the vector. This is destructive!

Example:

(def test-push-vec (vec))
(test::assert-equal [1] (vec-push! test-push-vec 1))
(test::assert-equal [1] test-push-vec)
(test::assert-equal [1 2] (vec-push! test-push-vec 2))
(test::assert-equal [1 2] test-push-vec)
(test::assert-equal [1 2 3] (vec-push! test-push-vec 3))
(test::assert-equal [1 2 3] test-push-vec)

vec-remove!

Usage: (vec-remove! vector index) -> vector

Namespace: root

Remove the element at index from vector, shifting all elements after it to the left. This is destructive!

Example:

(def test-remove-nth-vec [1 2 3])
(test::assert-equal [1 2 3] test-remove-nth-vec)
(vec-remove! test-remove-nth-vec 1)
(test::assert-equal [1 3] test-remove-nth-vec)
(vec-remove! test-remove-nth-vec 1)
(test::assert-equal [1] test-remove-nth-vec)
(vec-remove! test-remove-nth-vec 0)
(test::assert-equal [] test-remove-nth-vec)

vec-slice

Usage: (vec-slice vector start end)

Namespace: root

Returns a slice of a vector (0 based indexes, end is exclusive).

Example:

(test::assert-equal [5 6] (vec-slice [1 2 3 4 5 6] 4 6))
(test::assert-equal [1 2 3] (vec-slice [1 2 3 4 5 6] 0 3))
(test::assert-equal [3 4 5] (vec-slice [1 2 3 4 5 6] 2 5))
(test::assert-equal [3 4 5 6] (vec-slice [1 2 3 4 5 6] 2))