Vector
Comparable to ordered collections (arrays/lists) in other languages (C++, JavaScript, Scala, Factor), a part of the stack can be marked as belonging together and thus be understood as one unit. With and the values lying between these markers are combined into a vector.
This can be used, for example, to transfer a variable number of parameters to InstantView® instructions.
Vectors in InstantView® can contain elements of different types. An example of a vector:
[ "Hallo" 1 5m NULL ]
Vectors exist on the stack in two different states:
- as a sequence of entries that start with and begins with ends
- as an entry containing the whole vector (without and ). A variable always contains a vector in this form.
InstantView® internally uses different representations for vectors, adapted to the elements they contain.
You can switch between these states using the # operator.
Operations with vectors are supported by the following instructions:
-> var | Assignment to a variable |
# | e1, ...en into a stack entry (shrink) or the reverse operation (explode) |
| | merge vectors, add an element to a vector (add), result is a new vector |
- | Remove vector element from a vector, result is a new vector |
= | compare two vectors |
Insert | Add an element to a vector |
GetElement | obtain the kth element of a vector |
Revert | Reversing the order of the elements of a vector |
GetVector | Construct vector (from the elements of a collection, ...) |
CreateVector(s) | create empty vector (pre-allocated for n elements) |
StringVector | Create a vector from a string |
Statements that accept vectors as input parameters are
SetFormat, SetSort, FillObox, UpdateObox, RemoveObox, SetSelection, PutLine, Insert, Remove, GetObject. . .
With the instruction iterate you can iterate over the elements of a vector.