1 array data type – Compaq DEC Text Processing Utility AA-PWCBD-TE User Manual
Page 42
DEC Text Processing Utility Data Types
3.1 Array Data Type
3.1 Array Data Type
An array is a structure for storing and manipulating a group of elements. These
elements can be of any data type. You create arrays with the CREATE_ARRAY
built-in procedure. For example, the following statement creates the array
new_array:
new_array := CREATE_ARRAY;
You can delete arrays with the DELETE built-in procedure.
When you create an array, you can optionally direct DECTPU to allocate a
specified number of integer-indexed array elements. DECTPU processes this
block of preallocated elements quickly. You can direct DECTPU to create such a
block of elements only at the time you create the array.
The following statement creates the array int_array, directs DECTPU to allocate
10 sequential, integer-indexed elements to the array, and specifies that the lowest
index value should be 1:
int_array := CREATE_ARRAY (10, 1);
Regardless of whether you specify a preallocated block of elements, you can
always add array elements dynamically. Dynamically added elements can be of
any data type except learn, pattern, program, or unspecified. You can mix the
data types of indexes in an array.
In the following code fragment, the array mix_array is created and the integer 1
is stored in the array element indexed by the marker mark1.
mix_array := CREATE_ARRAY;
mark1 := MARK (NONE);
mix_array {mark1} := 1;
mix_array {"Kansas"} := "Toto";
You can index dynamic elements with integers, even if this means that the array
ends up with more integer-indexed elements than you specified when you created
the array. DECTPU does not process dynamically added integer-indexed elements
as quickly as it processes preallocated elements.
To refer to an array element, use the name of an existing array variable followed
by the array index enclosed in braces ( { } ) or parentheses ( ( ) ). For example, if
you create an array and store it in the variable my_array, the following are valid
element names:
my_array{2}
my_array("fred")
To create an element dynamically for an existing array, use the new element
as the target of an assignment statement. The following statement creates the
element
"
string1
"
in the array my_array and assigns the element to the string
"
Topeka
"
:
my_array{"string1"} := "Topeka";
In the following example, the first statement creates an integer-indexed array,
int_array. The array has 10 elements; the first element starts at index 1. The
second statement stores a string in the first integer-indexed element of the array.
The third statement stores a buffer in the eighth element of the array. The
fourth statement adds an integer-indexed element dynamically. This new element
contains a string.
3–2 DEC Text Processing Utility Data Types