HP Pascal/iX Reference Manual (31502-90022)

4-: 16
.
.
a:= [1, 3, 5];
b:= [2, 4];
c:= [1..10];
x:= 9;
a:= a + b; { Union; a is now [1, 2, 3, 4, 5]. }
b:= c - a; { Difference; b is now [6, 7, 8, 9, 10]. }
c:= a * b; { Intersection; c is now []. }
c:= [2, 5] + [x] { Set constructor operands; c is now }
END. { [2, 5, 9]. }
Array Selector
An
array selector
accesses a component of an array. The selector follows
an array designator and consists of an ordinal expression in square
brackets. For a string or PAC type, an array selector accesses a single
component; for example, a character.
The ordinal expressions must be assignment compatible with the index
types of the array. An array designator can be any variable with an
array type that includes an array selector, a function call that returns
an array, or an array constant. The symbols (. and .) may replace the
left and right brackets, respectively. The list can be used to select a
component of a multiple-dimensioned array.
Syntax
Array_selector:
Example
PROGRAM show_arrayselector;
TYPE
a_type = ARRAY [1..10] OF integer;
VAR
m,n : integer;
s_array : ARRAY [1..3] OF 1..100;
multi_array : ARRAY [1..5,1..10] OF integer;
p : ^a_type;
BEGIN
s_array[2]:= 32;
m:= s_array[2]; { Assigns current value of 2nd }
{ component of s_array to m }
multi_array[2,9]:= m; { These two methods of }
multi_array[2][9]:= m; { assignment are equivalent. }
new(p);
p^[1]:= 1200;
n:= p^[m MOD 10 + 1] * m; { Array in the heap with computed }
END. { selector. }