tur/ref
stdlib/ref.tur
heap-allocated mutable reference cell with independent ownership.
Since: Phase B1
defstruct
Ref
(defstruct Ref [value : int])
heap-allocated single-value container with independent ownership.
Since: Phase B1
defopaque
RefHandle
(RefHandle)
defn
ref-new
(ref-new [value : int] :)
allocate a new Ref cell on the heap containing value.
Parameters
| value | the int64 value to store inside the Ref |
Returns
A RefHandle (an opaque :int pointer cast) to the new Ref cell.
Example
(def r (ref-new 42)) ; => RefHandle to Ref{42}
Since: Phase B1
defn
ref-get
(ref-get [r : RefHandle] :)
read the value stored in a Ref cell.
Parameters
| r | opaque Ref handle returned by ref-new |
Returns
The int64 value stored inside the Ref.
Example
(ref-get (ref-new 99)) ; => 99
Since: Phase B1
defn
ref-free
(ref-free [r : RefHandle] :)
free the Ref cell (shallow; does not free the contained value).
Parameters
| r | opaque Ref handle 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