Arrays

Common syntax

An array may be assigned at declaration with a literal array, that is a list of values, numbers or texts, or variable between curly braces.

array a = { 1, 2, 3 }

It may be assigned a constructor:

array a = array( 1, 2, 3 )

Array are virtual classes in Scriptol and have methods just as other type: text, dict, file, dir, etc...

Array are stacks

Elements may be pushed, poped, shifted or unshifted.

a.push(4)
dyn x = a.pop()
print x

Iterator

You can use iterator on arrays.
The methods begin, inc, end, dec allow to scan the array and return each element.

a.begin()                                  ` moves to the first element
while a[] <> nil                        ` tests if end of list reached
    print a[]                               ` prints the currently pointed out element
    a.inc()                                  ` moves to next element
/while

Interval

Parts of array may be replaced, inserted, removed by subscripting an interval.
An interval is assigned "nil" to be removed from the array.

print a[x .. y]         `displays a sub-array.
a[.. y] = b[1 .. 3]     `replaces range 0 to y in array a, with interval 1 to 3 in array b.
a[2 .. 8] = nil          `removes items in the range 1-8.