Contiguous non-owning view of items of the same schema with schema-level fixed size.
SpanStatic
Methods
assign |
(other --) |
Replaces the current view with the view described by other. |
Preconditions
other.size equals the current static size.
Postconditions
- Data matches
other.
- The static size is unchanged.
at |
(key -- ref) |
Returns Ref to the item at key. |
Preconditions
key in [0..current item count - 1].
data |
(-- ref) |
Returns the stored Ref to the first item. |
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 remaining view by one item when valid. |
Postconditions
valid is TRUE when an item was available.
- When
valid is TRUE, the remaining item count decreases by one.
size |
(-- count) |
Returns the current item count. |
slice |
(offset size -- theSpan) |
Returns a static span over the selected subrange. |
Preconditions
offset in [0..current item count].
size in [0..current item count - offset].
Examples
"SpanStatic" use
"control" use
{} () {} [
span: (10 20 30 40) toSpanStatic;
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 dynamic Span over the same range. |
spanStatic |
(-- theSpan) |
Returns a static span over the same range. |
stringView |
(-- theStringView) |
Returns StringView built from the same data and size. |
Runtime example: reverse iteration
"SpanStatic" use
"String" use
"control" use
{} Int32 {} [
span: (10 20 30) toSpanStatic;
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
toSpanStatic (source -- theSpan)
Converts supported sources to SpanStatic.
Text sources become SpanStatic<Nat8 Cref, size> over UTF-8 storage.
- Homogeneous non-
Ref Struct sources become static spans over their items.
- Any source that has a
.spanStatic method uses that method result.
Runtime example
"SpanStatic" use
"String" use
"control" use
{} Int32 {} [
numbers: (10 20 30) toSpanStatic;
("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
toSpanStatic2 (spanData spanSize -- theSpan)
Constructs SpanStatic directly from item data and item count.
spanData supplies the item schema and base Ref.
spanSize becomes part of the resulting schema.
Examples
"SpanStatic" use
"control" use
{} () {} [
span: (10 20 30) toSpanStatic;
part: @span.data 2 toSpanStatic2;
part.size printStack _:;
0 @part.at printStack _:;
1 @part.at printStack _:;
] "main" exportFunction
Expected Output During Compilation
2
Int32 Ref
Int32 Ref
Runtime example
"SpanStatic" use
"String" use
"control" use
{} Int32 {} [
span: (10 20 30 40) toSpanStatic;
part: 1 2 @span.slice;
("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=20
second=30
See also
- Span: Contiguous non-owning view of items of the same schema.
- String: UTF-8 string views, owned strings, formatting helpers, and text conversion utilities.
- Array: Growable array.