Skip to content
TurtleKitty edited this page May 10, 2019 · 3 revisions

vector

A vector is a contiguous array of values. A matrix is a vector composed of vectors.

constructors

(vector 1 2 3)          ; #(vector 1 2 3)
(vector 1 2 3 size: 5)  ; (vector: 1 2 3 null null)
(matrix 1 2 3)          ; #(vector 1 2 3)
(matrix (1 2) (3 4))    ; #(vector #(vector 1 2) #(vector 3 4))

messages

(def v (vector 1 2 3))
(def z (vector))  ; z is for zero elements

v.type   ; (vector)
v.0      ; 1
(v 0)    ; 1
v.2      ; 3

v.size      ; 3
z.size      ; 0
v.to-bool   ; true
z.to-bool   ; false
v.empty?    ; false
z.empty?    ; true

(v.has? 2)  ; true
(v.has? 5)  ; false

v.to-list   ; (1 2 3)
v.to-set    ; #(set (0 . 1) (2 . 3) (1 . 2))
v.to-table  ; #(table 2 3 1 2 0 1)

v.clone     ; #(vector 1 2 3)
v.pairs     ; ((0 . 1) (1 . 2) (2 . 3))
Clone this wiki locally