@include std.core
@include std.mem
smo Segment(nominal, str value)
-> @args // return all inputs
smo Segment(String _value)
value = _value:str
-> nominal:Segment(value)
smo combine(Segment[] segments)
@mut s = "":str // mutable
on Stack:arena(1024)
range(segments:len)
:while next(@mut u64 i)
// from null-termiated nstr result to str
s = str(s+segments[i].value+" ")
-- -- -> combined // end block x2, return
service main()
segments = Segment[]
:push("I think.":Segment)
:push("Therefore I am.":Segment)
print(segments:combine)
--
In the example, freeing the arena is safely delayed until printing. All operations are also zero-cost abstractions
over performant implementations at the core of the standard library. Furthermore:
smo definitions can fail and produce nominal values.
nominal declares a nominal type variation.
service runs safely; if a smo fails, memory is cleaned up.
@mut denotes mutable variables (their values change as the program runs).
on is automatically added as first argument - here to store string addition on a fast arena allocator.