PreviousNext
Help > EXTREME PROGRAMMING WITH RITTLE > Dynamic Arrays
Dynamic Arrays

Another useful feature of Rittle is the possibility to dynamically change the size of an array variable, or even convert a single variable into an array.

In order for that to be done, the variable needs to exist already (has been declared earlier with a “var” statement). Rittle provides a word “redim” which is used to change the dimensions of already existing variables. This feature significantly simplifies work with various lists and other structures with unknown length as the developer can expand or reduce the structure as per the needs on the go.

Example:

var int something[10];     ‘ the array is initially declared to have 10 elements
redim something[20];      ‘ the same array now has 20 elements

 

The word “redim” retains all existing data in the array, however if the new size is smaller than the old one, the excess elements at the end of the array will be lost. A special consideration must be given to re-dimensioning of multi-dimensional arrays. Although it is technically possible, the results might differ from the expectations, and the data elements might end up shifted away from their original indexes, so ideally re-dimensioning should be done on one-dimensional arrays only.