No matching definitions.

tur/ref

stdlib/ref.tur

heap-allocated mutable reference cell with independent ownership.

ref-new allocates; ref-get reads; ref-set writes; ref-free releases.

Since: Phase B1

defstruct

Ref

(defstruct Ref [value :int])

heap-allocated single-value container with independent ownership.

Since: Phase B1

defopaque

RefHandle

(defopaque RefHandle [A] :int)
defn

ref-new

(ref-new [A])

allocate a new Ref cell on the heap containing value.

valuethe value to store inside the Ref; its type pins A

A (RefHandle A) -- an opaque :int pointer cast -- to the new Ref cell.

(def r (ref-new 42))    ; => (RefHandle int)
(def f (ref-new 7.25))  ; => (RefHandle float)

Ownership:

A single-word A (int / float / cstr / opaque / :heap pointer) is stored
directly. A MULTI-WORD by-value A rides its slot as a heap box pointer
the cell then owns; ref-free is shallow and does not free it, so read it
back with ref-get before freeing the cell if you need to keep it.

Since: Phase B1

defn

ref-get

(ref-get [A])

read the value stored in a Ref cell.

r(RefHandle A) returned by ref-new

The stored value, at type A. Declaring : A here is safe for the same reason it is on vec-get: an inline-C body is NOT return-specialized, so the emitted base still hands back the raw int64 word and only the checker learns A. (A body that WERE return-specialized would mint a double base for A=float whose carrier read numerically converts the bits instead of reinterpreting them -- that is what vec.tur's header warns about, and it is a warning about specialized bodies, not about the declaration.)

(ref-get (ref-new 99))    ; => 99
(ref-get (ref-new 7.25))  ; => 7.25, no ascription needed

Since: Phase B1

defn

ref-free

(ref-free [A])

free the Ref cell (shallow; does not free the contained value).

r(RefHandle A) returned by ref-new

Since: Phase B1

definstance

Clone[Ref]

(definstance Clone [Ref])

deep-clone a Ref struct: allocates a new Ref with an independent copy of the value.

Since: Phase B1