MPE/iX Shell and Utilities Reference Manual, Vol 1
dc(1) MPE/iX Shell and Utilities dc(1)
An array is just a list of values. Values in the list are referred to by number; for example, you
can ask for the 12th value in the list. The numbers used to refer to values are called the sub-
scripts of the array. The beginning of the list has the subscript 0 and the maximum subscript
for any array is 2047.
There are two array operations:
:x stores a value in array x. The operation begins by popping a number off the stack and
uses it as the subscript into the array. dc then pops another value off the stack and
stores this value in the array using the given subscript.
;x obtains a value from the array x. dc pop the top number off the stack to use as a sub-
script into the array. It then places the value found at that subscript on the stack. The
operation does not affect the value inside the array; it just takes a copy of the value.
If you use ; to obtain a value from an array, but you have not yet used : to store a value in
that position, dc automatically puts a zero onto the stack (as if there were a zero in that posi-
tion).
In an earlier section, the S and L operators were used to push and pop the scalar value of a
register onto the register’s stack. These operators also push and pop the array component of a
register. This is done at the same time that the scalar values are being pushed or popped with
some differences in the details of how operations work. Where L popped the top of the regis-
ter’s scalar stack onto the main stack, the array operation simply pops the top of the register’s
array stack then discards the result. Where S popped the top of the main stack and pushed it
onto the register’s scalar stack, the array operation simply hides the current array values.
Again, both the scalar and array operations are caused by the same operator at the same time.
The following example shows how the S and L operations can be used to save or hide the
scalar and array values of a register. The operations
11sa121:alap1;apc
store 11 in a and 12 in a[1] then print the two values and finally clear the main stack. The
register a now has the scalar value 11 and the array element a[1] now has the value 12.
Next, the operations
0Salap1;ap
save the current array and scalar values associated with the register and print the new values
for a and a[1] (which are now zero). The old array and scalar values of the register have
been saved on the register’s stack. You can change the value of the register or any of the array
elements without affecting these saved values. To restore the old values, execute
Lalap1;ap
This pops the current array and scalar values off of the register stack thus making the old val-
ues visible again. The restored values are then printed.
Commands and Utilities 1-163