Chapter 4. Arrays

Overview

Every programming language provides for arrays. Sometimes they are referred to as tables. This basic data structure allows you to build lists of "like elements," which can be stored, searched, sorted, and manipulated by other basic programming operations.

Rexx's implementation of arrays is powerful but easy to use. Arrays can be of any dimensionality. They can be a one-dimensional list, where all elements in the array are of the same kind. They can be of two dimensions, where there exist pairs of entries. In this case, elements are manipulated by two subscripts (such as I and J). Or, arrays can be of as many dimensions as you like. While Rexx implementations vary, the usual constraint on the size and dimensionality of array is memory. This contrasts with other programming languages that have specific, language-related limitations on array size.

Rexx arrays may be sparse. That is, not every array position must have a value or even be initialized. There can be empty array positions, or slots, between those that do contain data elements. Or arrays can be dense, in which consecutive array slots all contain data elements. Figure 4-1 below pictorially shows the difference between sparse and dense arrays. Dense arrays are also sometimes called nonsparse arrays.

Arrays may be initialized by a single assignment statement. But just like other variables, arrays are defined by their first use. You do not have to predefine or preallocate them. Nor must you declare a maximum ...

Get Rexx Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.