Arrays are typically found in most programming languages, but the version that is present in SIMPOL can be considered to be a superset of the functionality provided in most implementations. The first significant difference is that array is a type of its own. Also, most languages require that arrays be pre-specified to be of a specific size and type. Many automatically start at index 0, others allow a base index to be specified. In SIMPOL the array type is very flexible, although this also comes at a price.
Firstly, arrays are not required to be made up of only one type. It is perfectly acceptable to assign different data types to different elements of the array. This may not be a clever thing to do in all cases, but it is possible. Another interesting feature of the array type is that at each level of the array it is possible to have elements present. That means that it is possible to create a multidimensional array that looks like this:
array a,b datetime dt dt =@ datetime.new() dt.setnow() a =@ array.new() b =@ array.new() a = "Week Info" a = 10 a[1,0] = "Monday" a[1,1] =@ dt a = 20 a[2,0] = "Tuesday" a[2,1] =@ dt b["array a"] =@ a a =@ .nul
In the preceding example the majority of the capabilities of the array can
be observed. Arrays can be indexed numerically or via strings or both. They
can have values at every level of a multidimensional array, not just at the
lowest level. Even the null element
a can have a value
or an object assigned to it. Any element can contain a value or a reference
to an object. In the example above, the array
b in element
b["array a"] still contains a reference to the array object
that was originally referenced by the variable
a even after
that variable has been set to
.nul. As long as a reference
to the object exists, the object itself still exists, and all elements that
are associated with it.
As can be seen from the preceding example, it is possible to build quite complex arrays. Arrays can also be used in some cases in place of user-defined types. It is, of course, possible to create an array of user-defined type. The approach taken is left to the programmer, but it is strongly recommended that a consistent use is made of the array, since if they are used with varying data types it is entirely possible that an incorrect assignment may occur causing a type mismatch runtime error.
It is important to realize that to detect if an array element is empty
(as in not assigned), it is only necessary to test the value of the element
in question. It is not an error to assign from an unassigned element. The
value of any unassigned element is