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 [A])

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 [A])

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 [A])

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! [A])

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! [A])

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! [A])

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 [A])

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.

defn

tur-vec-homog__

(tur-vec-homog__ [A])

internal: compile-time element homogeneity check.

defmacro

vec-homog-chain__

(vec-homog-chain__ [& xs])

internal: pairwise-chain tur-vec-homog__ over xs.

defn

vec-empty-like__

(vec-empty-like__ [A])

internal: a fresh empty Vec[A] whose element type A

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. The element type A may be any single-word type (:int, :cstr, :bool, :nil, :float, an opaque handle, or a heap struct/ADT pointer); elements are stored through an :int carrier slot, so a :float element round-trips as a bit-reinterpret. The result's static type is a genuine (Vec A) -- its head carries the concrete element type -- so `(show (vec-of "a" "b"))` renders "[a b]" and `(eq? (vec-of "a") (vec-of "b"))` compares by the element's Eq instance rather than by carrier identity. The handle composes with vec-len, vec-get, vec-push!, etc.; vec-get returns :A, so a non-int element is read with an ascription, e.g. (:: (vec-get v 0) :float). 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. Aggregate (multi-word struct/ADT) element types are not supported by the carrier slot; those need a per-element typed layout (see TS3b). Note: each element expression is evaluated exactly once (the first is bound once and reused as both the type witness and the first push). Note: under -Xdata-literals, a [...] vector in expression position lowers to this macro, so [1 2 3] is sugar for (vec-of 1 2 3). See docs/guides/data-literals-guide.md.

(vec-of)        ; => empty Vec
  (vec-of 1 2 3)  ; => Vec containing 1, 2, 3
  [1 2 3]         ; => same, with -Xdata-literals

Since: Phase 2 cons-in-docs cleanup

defn

vec-eq?

(vec-eq? [v1 : int v2 : int ^fat 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

defn

vec-data-get__

(vec-data-get__ [data ptr<void> i : int] :)

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

defn

vec-data-get-checked__

(vec-data-get-checked__ [data ptr<void> i : int len : int] :)

bounds-checked indexed read over a raw data ptr.

defn

vec-get-byval

(vec-get-byval [A])

by-value Vec[A] indexed read (Option C twin of vec-get).

defn

vec-eq-loop

(vec-eq-loop [^Eq A])

pure-Turmeric element-wise Vec[A] comparison (TCO'd index loop).

xfirst Vec[A]
ysecond Vec[A]
icurrent index (start at 0)
lenshared length (both vecs are known equal-length by the caller)

true if x[i..len) equals y[i..len) under Eq[A].

(vec-eq-loop a b 0 (vec-len a))  ; => true

Since: Phase M4c (TCO-in-ABI-specs)

definstance

Eq[Vec]

(definstance Eq [Vec])

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