Skip to content

Arrays, Lists

Kameron Brooks edited this page Dec 26, 2018 · 3 revisions

ILists

Anything that implements the IList interface can be used like an array. This includes Arrays, Lists and ArrayLists. Anything in this documentation that applies to an Array will also apply to any implementer of IList.

Element Access

Elements in an array can be accessed in several ways.

Integer

The most common way is to accessed with an integer index. This is the way you are familiar with if you are familiar with c/c#.

arr[0];   // Get element at index 0 from array

This operation is read or write, the element can be read from and assigned to.

Array

You can also access elements with another array of indices to get or set multiple values in an array

arr [ [0,1,2] ];  // This will return a new array that contains the elements at index 0, 1, and 2  in the original array

I will show more interesting uses for this feature later in this page

.last

You can get the last index of an array by using the .last keyword inside the square brackets

arr[.last];      // Returns the last element of the array
arr[.last - 1];  // Returns the second to last element of the array

Interp Operator

You can use the interp operator .. to return a list of integers between 2 integers (including the first and last integers)

0..99;   // Returns an integer array that contains integers 0 through 99   [0,1,2,3,...98,99]
99..0;   // Returns an integer array that contains integers 99 though 0    [99,98,97,...,1,0]
-50..50; // Returns an integer array that contains integers -50 though 50
n..m;    // Returns an integer array that contains integers n though m