swap
Builtin index · Collections & strings
result =swap(b)/read(b)
Input: b · Output: result
What it is
b is a double_buffer handle. swap atomically exchanges front and back (returns Nothing); read returns the stable front value. Writers fill the spare half and swap when the frame is whole; a reader never sees a partly-written frame.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = swap(b) / read(b) | b —not documented yet | result — | Returns the stable front value from read — whatever type was written into the buffer; swap hands back no value. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
b = double_buffer(1)
b.write(2)
print(b.read()) # 1 -- the write above is not visible yet
b.swap()
print(b.read()) # 2 -- now it is
1 2
from collections-strings
How it works
double_buffer(initial) (§ data structures pass, 2026-09-01, primitive. "write" on a Value::DoubleBuffer is a guarded arm further up this match (next to Value::File/ Value::Serial's own "write" arms); "double_buffer"/ "read"/"swap" have no competing meaning anywhere else.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
read — documented in the same entry.