@include std.builtins
@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)
&s = "":str // mutable
on Stack:arena(1024)
range(segments:len)
:while next(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.
& denotes mutable variables.
on is automatically added as first argument (here to store string addition on a fast arena allocator).