HP Pascal/iX Reference Manual (31502-90022)

9- 15
PACKED ARRAY[u..v] of t; the procedure pack
(a, i, z)
assigns components
of the unpacked array
a
, starting at component
i
, to each component of
the packed array
z
.
Because all the components of
z
are assigned a value, the normalized
value of
i
must be less than or equal to the difference between the
lengths of
a
and
z
+ 1; for example,
i
-m+1 <= (n-m) - (v-u) + 1.
Otherwise, it is an error when pack attempts to access a nonexistent
component of
a
.
The component types of arrays
a
and
z
must be type identical. The index
types of
a
and
z
, however, may be incompatible.
The call pack
(a, i, z)
is equivalent to:
BEGIN
k:= i;
FOR j:= u TO v DO
BEGIN
z[j]:= a[k];
IF j <> v THEN k:= succ(k);
END;
END;
where k and j are variables that are type compatible with the index type
of
a
and the index type of
z
, respectively.
Example
PROGRAM show_pack (input,output);
TYPE
clothes = (hat, glove, shirt, tie, sock);
VAR
dis : ARRAY [1..10] OF clothes;
box : PACKED ARRAY [1..5] of clothes;
index: integer;
.
.
BEGIN
.
.
index:= 1;
pack(dis,index,box); { After pack executes, box contains }
. { the first 5 components of dis. }
.
index:= 8;
pack(dis,index,box); { An error results when pack attempts }
. { to access nonexistent 11th component }
. { of dis. }
END.
unpack
Usage
unpack
(z, a, i)
Parameters
z
Any PACKED ARRAY [u..v] of t.
a
Any ARRAY [m..n] of t.
i
An expression that is type compatible with the index of the
non-packed array.