5.04 Array Commands

APPEND

Function:

Adds values to the end of an array.

Syntax:

APPEND array, val [, val [, ...]]
array
An array-variable.
val
Any value or expression

Example:

append a, 1                    // a = {1)
append a, 2                    // a = {1,2)
append a, 3                    // a = {1,2,3)

INSERT

Function:

Inserts values into an array at the index position.

Syntax:

INSERT array, index, value [, value [, ...]]]
array
An array variable.
index
Position in the array.
value
Any value or expression

Notes:

The new entry is inserted into the array at the position specified. All entries from the next position are moved to make room for the new entry.

If the index value is less than the origin, the new entry is inserted at the beginning of the array.

If the index value is greater than the range, it is treated as an append and the new entry is added at the end of the array.

Example:

a = {1,2,3}                    // a = {1,2,3)
insert a, 1, 99                // a = {99,1,2,3}
insert a, 0, 88                // a = {88,99,1,2,3}
insert a, 10, 77               // a = {88,99,1,2,3,77}

DELETE

Function:

Deletes elements from an array at the index position.

Syntax:

DELETE array, index [, count] 
array
An array variable.
index
Position in the array.
count
The number of the elements to be deleted.

RANGE

Function:

Size an array and provide a range of index values.

Syntax:

RANGE array([lb to] ub[, ...]) [, ...]

where:

lb
the lower bound of this array. If not provided the lower bound of an array defaults to 1.
ub
the upper bound of this array.

Notes:

By default the lower bound of an array is always 1.

The RANGE command can be used to assign arrays and to provide a range of values for the subscripts including an alternative lower bound.

If RANGE is used to create a new array, the created array will be empty.

If RANGE is used to resize an existing array, any elements outside the bounds will be deleted. Any new elements created will be empty. All other elements will remain unchanged.

Example:

range v1(-4 to 7)
range v2(1 to 2, 3 to 4)
range m(1 to 3, -1 to 1)
put " m =" m     //display m = {{,,},{,,},{,,}}

Use the RANGE command to create arrays to be used as matrices. See 5.03 Matrix Operations.

ORIGIN/RANGE

Function:

Returns the lowest and highest current index values of an array.

Syntax:

ORIGIN(array[(dim[, ...])]) 
RANGE(array[(dim[, ...])]) 

where:

dim
is the array dimension whose bound is returned. Note that only the bound of the lowest supplied dimension is returned.

Example:

range v1(-4 to 7)
range v2(1 to 2, 3 to 4)
...
put origin(v1)     // displays -4
put range(v1)     // displays 7
...
put origin(v2)     // displays 1
put range(v2(2))  // displays 3

lynplex/lp0504.txt · Last modified: 2011/09/08 16:07 (external edit)