The following array operations should be useful:
fill = proc (lb, cnt: int, elem: t) returns (array[t]) signals (negative_size) effects If cnt < 0, signals negative_size. Returns a new array with low bound lb and size cnt, and with elem as each element; if this new array would have high bound < int_min or > int_max, signals failure.So for example array[int]$fill(0, n, 0) creates an array of n zeroes with lower bound at 0.
indexes = iter (a: array[t]) yields (int) effects Yields the indexes of a from the low bound of a[pre] to the high bound of a[pre]. Note that 'indexes' is unaffected by any modifications done by the loop body.You can use this for easy looping, e.g., by
for i : int in array[int]$indexes(z) do ... end
low = proc (a: array[t]) returns (int) effects Returns the low bound of a. high = proc (a: array[t]) returns (int) effects Returns the high bound of a.
size = proc (a: array[t]) returns (int) effects Returns a count of the number of elements of a.
create = proc (lb: int) returns (array[t]) effects Returns a new, empty array with low bound lb. new = proc ( ) returns (array[t]) effects Returns a new, empty array with low bound 1. addh = proc (a: array[t], elem: t) modifies a. effects If extending a on the high end causes the high bound or size of a to be outside the defined range of integers, signals failure. Otherwise extends a by 1 in the high direction and stores elem as the new element. addl = proc (a: array[t], elem: t) signals (overflow) modifies a. effects If extending a on the low end causes the low bound or size of a to be outside the defined range of integers, signals failure. Otherwise extends a by 1 in the low direction and stores elem as the new element.
remh = proc (a: array[t]) returns (t) signals (bounds) modifies a. effects If a is empty, signals bounds. Otherwise shrinks a by removing its high element and returning the removed element. reml = proc (a: array[t]) returns (t) signals (bounds) modifies a. effects If a is empty, signals bounds. Otherwise shrinks a by removing its low element and returning the removed element.
top = proc (a: array[t]) returns (t) signals (bounds) effects If a is empty, signals bounds; otherwise returns a[high(a)].
Here are a few on integers:
mod = proc (x, y: int) returns (int) signals (zero_divide, overflow) effects Signals zero_divide if y = 0. Otherwise returns the integer remainder of dividing x by y; signals overflow if the result would lie outside the represented interval.
max = proc (x, y: int) returns (int) effects Returns the larger of x and y.
from_to_by = iter (from, to, by: int) yields (int) effects Yields the integers from 'from' to 'to', incrementing by 'by' each time, that is, yields 'from', 'from'+'by', ... ,'from'+n*'by', where n is the largest positive integer such that 'from'+n*'by' <= ( >= when 'by' is negative) 'to' . If 'by' = 0, then yields 'from' indefinitely. Yields nothing if 'from' > 'to' and 'by' > 0, or if 'from' < 'to' and 'by' < 0. from_to = iter (from, to: int) yields (int) effects Identical to from_to_by('from', 'to', 1).So again, you can loop using
for i : int in int$from_to(1, n) do ... end