build irregular array
To build an irregular array, the individual one-dimensional sub-arrays of a multi-dimensional array are created separately, then assembled into the complete irregular array.  Alternatively, a regular array can be converted into an irregular array by detaching subarrays, redimensioning them, then reattaching them (ATTACH, REDIM, ATTACH).

The five one-dimensional arrays created and assembled by

  DIM a[3,7]

in the preceding example could also be created and assembled by either of the following two functions:

FUNCTION DimDemo1 ()
  SHARED a[]             ' let's say a[] is a SHARED array
  DIM a[3,]               ' create upper dimension of a[]
  DIM a0[7]               ' create a0[7] to be data in a[0, ]
  DIM a1[7]               ' create a1[7] to be data in a[1, ]
  DIM a2[7]               ' create a2[7] to be data in a[2, ]
  DIM a3[7]               ' create a3[7] to be data in a[3, ]
  ATTACH a0[] TO a[0,]   ' attach a0[] to a[0, ]
  ATTACH a1[] TO a[1,]   ' attach a1[] to a[1, ]
  ATTACH a2[] TO a[2,]   ' attach a2[] to a[2, ]
  ATTACH a3[] TO a[3,]   ' attach a3[] to a[3, ]

FUNCTION DimDemo2 ()
  SHARED a[]              ' let's say a[] is a SHARED array
  DIM a[3,]               ' create upper dimension of a[]
  FOR i = 0 TO 3         ' for each element of upper dimension
    DIM n[7]              ' create an array with 7 data elements
    ATTACH n[] TO a[i,]  ' attach to upper dimension element
  NEXT i                  ' next element of upper dimension

The ATTACH statement first verifies the destination array or node is empty, then swaps it with source array or node.  This has the effect of attaching the source to the destination, leaving the source empty.  SWAP is identical except the destination is not checked for zero before the arrays or nodes are swapped.

  ATTACH xx[] TO yy[]
  ATTACH xx[] TO nn[a, b, ]
  ATTACH nn[a, b, ] TO xx[]
  ATTACH nn[a, b, ] TO oo[c, d, e, ]
  SWAP b[], c[]
  SWAP b[], c[n, ]
  SWAP a$[n, ], a$[m, ]

It follows that irregular arrays may have different number of nodes down various branches of the tree structure.  Nodes that contain a zero are called empty nodes and mark the termination of the tree structure prior to arriving at data.  It cannot be known at compile time or runtime what nodes will be empty, the structure of programs must assure that accesses beyond empty nodes are not attempted.  It is wise to leave bounds checking enabled during program development to catch errors of this kind because memory corruption and development environment crashes could result.