Contiguous non-owning view of items of the same schema.
Span
Methods
Postconditions
- Data and size match
other.
Postconditions
- Result can be
NILif the item count is0.
iter
(-- iter) Returns a forward iteration source over the current items.Postconditions
- The iteration range matches
span.
iterReverse
(-- iter) Returns a reverse iteration source over the current items.Postconditions
- The iteration starts at the last item and proceeds backward.
next
(-- item valid) Returns the current item and advances the view by one item when valid.Postconditions
size
(-- count) Returns the current item count.slice
(offset size -- theSpan) Returns a span over the selected subrange.Preconditions
offsetin [0..current item count].size(the argument) in [0..current item count - offset].
Examples
"Span" use
"control" use
{} () {} [
span: (10 20 30 40) toSpan;
part: 1 2 @span.slice;
part.size printStack _:;
0 @part.at printStack _:;
1 @part.at printStack _:;
] "main" exportFunction
Expected Output During Compilation
2
Int32 Ref
Int32 Ref
span
(-- theSpan) Returns a span over the same range.Runtime example: reverse iteration
"Span" use
"String" use
"control" use
{} Int32 {} [
span: (10 20 30) toSpan;
it: @span.iterReverse;
item0: ok0: @it.next;;
item1: ok1: @it.next;;
item2: ok2: @it.next;;
item3: ok3: @it.next;;
("ok0=" ok0 LF
"v0=" item0 new LF
"ok1=" ok1 LF
"v1=" item1 new LF
"ok2=" ok2 LF
"v2=" item2 new LF
"ok3=" ok3 LF) printList
0
] "main" exportFunction
Expected Output
ok0=TRUE
v0=30
ok1=TRUE
v1=20
ok2=TRUE
v2=10
ok3=FALSE
toSpan (source -- theSpan)
Converts supported sources to Span.
Textsources becomeSpan<Nat8 Cref>over UTF-8 storage.- Homogeneous non-
RefStruct sources become spans over their items. - Any source that has a
.spanmethod uses that method result.
Runtime example
"Span" use
"String" use
"control" use
{} Int32 {} [
numbers: (10 20 30) toSpan;
("size=" numbers.size LF
"first=" 0 @numbers.at new LF
"last=" 2 @numbers.at new LF) printList
0
] "main" exportFunction
Expected Output
size=3
first=10
last=30
toSpan2 (spanData spanSize -- theSpan)
Constructs Span directly from item data and item count.
spanDatasupplies the item schema and baseRef.spanSizesupplies the item count.
Examples
"Span" use
"control" use
{} () {} [
span: (10 20 30) toSpan;
part: @span.data 2 toSpan2;
part.size printStack _:;
0 @part.at printStack _:;
1 @part.at printStack _:;
] "main" exportFunction
Expected Output During Compilation
2
Int32 Ref
Int32 Ref
Runtime example
"Span" use
"String" use
"control" use
{} Int32 {} [
span: (10 20 30 40) toSpan;
part: @span.data 2 toSpan2;
("size=" part.size LF
"first=" 0 @part.at new LF
"second=" 1 @part.at new LF) printList
0
] "main" exportFunction
Expected Output
size=2
first=10
second=20
See also
- Array: Growable array.
- SpanStatic: Contiguous non-owning view of items of the same schema with a schema-level fixed size.
- String: UTF-8 string views, owned strings, formatting helpers, and text conversion utilities.
- algorithm: Collection interfaces, comparison helpers, iteration adapters, and view slicing utilities.