Arrays

Copy

arraycopy(src, dst)
arraycopy(src, idx0, dst , idx1, length)
e.g.
a = [1, 2, 3]
b = [0, 0, 0, 4, 5]
arraycopy(a, b)
b      ==> [1, 2, 3, 4, 5]

Sublist

array [ start .. end ]
array [ start ]

array[start..end] returns a partial list of list. When length is omitted, it returns a partial list from start to the end.

e.g.
a = [1,2,3,4]
a[1..2]    ==> [2, 3]
a[1]    ==> [2, 3, 4]

List Processing

map(list, function)

map() applies function to each element of list and creates an array from the results.

e.g.
> map([1, 2, 3], function (x)  x * 100)
[100, 200, 300]
filter(list, function)

filter() applies function to each element of list and build an array from the elements that the function returns true.

e.g.
> filter([1, 2, 3], function (x)  x > 1)
[2, 3]

Conversion to primitive array type

(int[])[1,2,3,4,5]
(float[])[1,2,3,4,5]
(byte[])[#1,#2,#3,#4,#5]
(char[])['a', 'b']
(boolean[])[true, false]

Array concatenation can be used for the same purpose.

int[0] + [1,2,3,4,5]
float[0] + [1,2,3,4,5]
byte[0] + [#1,#2,#3,#4,#5]
char[0] + ['a', 'b']
boolean[0] + [true, false]

Back