tur/safe
bounds-checked operations returning Option or Result.
Since: Phase U4
array-get
(array-get [arr :ptr<void> idx :int] :ptr)
bounds-checked array read; returns a heap-allocated Option struct.
| arr | pointer to an int64_t array | |
| idx | zero-based index to read |
A :ptr to an option struct { bool is_some; int64_t value; }. is_some is false when idx is out of the v1 safe range.
(def opt (array-get arr 3))
Since: Phase U4
array-set
(array-set [arr :ptr<void> idx :int value :int] :int)
bounds-checked array write; returns 1 on success, 0 on out-of-range index.
| arr | pointer to an int64_t array | |
| idx | zero-based index to write | |
| value | value to store |
1 if the write succeeded, 0 if idx was out of the v1 safe range.
Since: Phase U4
array-slice
(array-slice [arr :ptr<void> start :int len :int] :ptr)
create a { ptr, len } slice view starting at start for len elements.
| arr | source int64_t array pointer | |
| start | first element index (offset in int64_t units) | |
| len | number of elements in the view |
A :ptr to a { void *ptr; size_t len; } slice struct.
Since: Phase U4
with-c-string
(with-c-string [s :cstr f :ptr] :ptr)
pass a Turmeric cstr to a callback function and return its result.
| s | cstr value to pass (already a C string in v1) | |
| f | function pointer accepting a cstr; called with s |
Whatever f returns, as :ptr.
Since: Phase U4
from-c-string
(from-c-string [s :cstr] :cstr)
return a Turmeric cstr from a C string (no-copy in v1).
| s | C string to wrap |
The same :cstr pointer (identity in v1).
Since: Phase U4
box
(box [v :int] :ptr)
heap-allocate an int64 value and return a pointer to it.
| v | integer value to box |
A :ptr to a newly heap-allocated int64_t cell containing v.
(def p (box 42))
Since: Phase U4
unbox
(unbox [p :ptr] :int)
read the int64 value from a heap pointer created by box.
| p | pointer from box |
The int64 value stored at p.
(unbox (box 42)) ; => 42
Since: Phase U4