@include std.core
@include std.mem
def Segment(nominal, str value)
return @args // return all inputs
def Segment(String _value)
value = _value.str() // convert from all String types
return nominal.Segment(value)
def combine(Segment[] segments)
@mut s = str("") // convert "" to mutable str
on Stack.arena(1024) // automatic use when needed
segments.len().range().while next(@mut u64 i)
then s = str(s+segments[i].value+" ")
return combined
service main()
segments = Segment[]
.push(Segment("I think."))
.push(Segment("Therefore I am."))
segments
.combine()
.print()
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. Code blocks either end or return. Furthermore:
def functions that can fail and produce nominal values.
service functions run safely; if a def fails, resources are cleaned up.
nominal declares a nominal type variation.
then is followed by the last expression of the code block.
@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.
. member values or curries a first argument into functions.