No matching definitions.

tur/vec

stdlib/vec.tur

typed Vec[A]: parameterized growable array.

Since: Phase TC1-A

defstruct

Vec

(defstruct Vec [A])

parameterized growable array with element type A.

Since: Phase TC1

defn

vec-new

(vec-new)

allocate a new empty Vec[A].

A new empty Vec[A] with len=0 and cap=0.

(vec-new)  ; => empty Vec

Since: Phase TC1

defn

vec-len

(vec-len [v :int])

return the number of elements in a Vec[A].

vVec[A] pointer

Element count.

(vec-len my-vec)  ; => 3

Since: Phase TC1

defn

vec-get

(vec-get [v :int i :int])

return the element at index i (bounds-checked).

vVec[A] pointer
izero-based index

The element at index i (typed A, stored as int64_t).

(vec-get my-vec 0)  ; => first element

Since: Phase TC1

defn

vec-push!

(vec-push! [v :int val :int])

append an element to the Vec[A].

vVec[A] pointer
valelement of type A to append
(vec-push! my-vec 42)

Since: Phase TC1

defn

vec-pop!

(vec-pop! [v :int])

remove and return the last element of a Vec[A].

vVec[A] pointer

The last element of type A (as int64_t), or 0 if empty.

(vec-pop! my-vec)  ; => last element

Since: Phase TC1

defn

vec-set!

(vec-set! [v :int i :int val :int])

overwrite the element at index i.

vVec[A] pointer
izero-based index
valnew element value of type A
(vec-set! my-vec 0 99)

Since: Phase TC1

defn

vec-free

(vec-free [v :int])

free a Vec[A] and its data buffer.

vVec[A] pointer to free
(vec-free my-vec)

Since: Phase TC1

defmacro

vec-push-each__

(vec-push-each__ [v & xs])

internal helper for the vec-of macro.

defmacro

vec-of

(vec-of [& xs])

variadic Vec[A] literal.

& xs -- zero or more elements, all of type A.

A fresh Vec[A] populated with xs in order. Carrier type is :int (the same handle returned by vec-new), so it composes with all of vec-len, vec-get, vec-push!, vec-eq?, etc. Note: all elements must unify to a single type. Mixing types -- e.g. (vec-of 1 "x" 3.14) -- is a type error (TUR-E0001 on the offending element). For heterogeneous fixed-arity collections, use tupleN.

(vec-of)        ; => empty Vec
  (vec-of 1 2 3)  ; => Vec containing 1, 2, 3

Since: Phase 2 cons-in-docs cleanup

defn

vec-eq?

(vec-eq? [v1 :int v2 :int cmp-fn])

compare two Vec[A] element-wise using a comparator.

v1first Vec[A]
v2second Vec[A]
cmp-fncomparator fn [a :int b :int] :bool

true if both vecs have the same length and all element pairs satisfy cmp-fn.

(vec-eq? va vb (fn [a b] (= a b)))  ; => true

Since: Phase TC1

definstance

Eq[Vec]

(definstance Eq [Vec])

element-wise equality using the element type's Eq instance.