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
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
An opaque :int handle (pointer cast) to the new Ref cell.
Example
(def r (ref-new 42)) ; => handle to Ref{42}
Since: Phase B1
defn
ref-get
(ref-get [r] :int)
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])
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