A commonly used built-in class is a vector of items.
A vector is an array that can dynamically expand or contract.
Items can be inserted within the vector.
Vector elements can be indexed, using the square bracket notation in the prior section.
A vector class instance is prepared by normal class construction and initialization.
The following is an example:
v = ^^ vector( 'a', 'b', 'c' )
|
The above method of constructing a vector is somewhat ungainly for such a common programming task.
Consequently, roo! supports a shorter alternative that uses curly braces:
v = { 'a', 'b', 'c' } |
Methods can be applied after the right curly brace:
say { 'a', 'b', 'c' } ~ toString |
Vectors can be arbitrarily nested:
vectorOfvectors = { 'a', 'b', { 'x', 'y', 'z' } } |
A vector of vectors can be composed:
vectorOfvectors = { { 'a', 'b', 'c' }, { 'x', 'y', 'z' } } |
An empty vector can be prepared:
e = { } |