beautypg.com

Getinterval – AMT Datasouth PAL User Manual

Page 114

background image

getinterval

108

getinterval

Description

Recover a range of data from an array or string object.

Usage

AnyArray IndexInt LengthInt

getinterval

SubArray

AnyStr IndexInt LengthInt

getinterval

SubStr

AnyArray

Array. Array object containing desired array sub-range to recover.

AnyStr

String. String object containing desired string sub-range to recover.

IndexInt

Integer. When used with AnyArray, index of first data object in sub-range within
array. Arrays begin with index zero. When used with AnyStr, index of first
character in sub-range within string. Strings begin with index zero.

LengthInt

Integer. When used with AnyArray, number of data objects in sub-range within
array. When used with AnyStr, number of character in sub-range within string.

SubArray

Array. Array containing objects from the AnyArray sub-range specified.

SubStr

Any. String containing characters from the AnyStr sub-range specified.

Comments

In the first variant, the operator recovers the LengthInt objects starting at index IndexInt within the
array AnyArray. Array indexes range from zero to N-1, where N is the number of elements in the
array. The operator creates the new array SubArray from duplicates of the AnyArray objects. For
composite objects, the duplicate objects share their data with the original objects in the AnyArray.

In the second variant, the operator recovers the LengthInt characters starting at index IndexInt
within the string AnyStr. String character indexes range from zero to N-1, where N is the number
of characters in the string. The operator creates the new string SubStr from the characters copied
from AnyArray.

For both variants, the specified sub-range may exceed the range of either AnyArray or AnyStr.
The intepreter will automatically adjust the requested length to the limits of the source object.

The programmer may also specify a negative value for LengthInt. A negative LengthInt value
instructs the interpreter to index into AnyArray or AnyStr starting from the end. Therefore, the last
object in AnyArray, or the last character in AnyStr will have an IndexInt value of zero. As a
result, "[0 1 2 3 4 5] 1 -2 getinterval" will return "[3 4]." For strings, "(ABCDE) 2 -3
getinterval" will return "(ABC)."

Hints

PAL will automatically adjust LengthInt for the remaining number of objects left in AnyArray, or
characters left in AnyStr. By specifying a LengthInt equal to or greater than the length of
AnyArray or AnyStr, the programmer can recover the entire end of the array or string. For