Sequences
def a = [10, 20, 30, 40, 50]; // sequence of integers
def b = [35, 1.2, "foo", null, false]; // mixed types
def c : String[] = ["a", "b", "c"]; // explicit type
def d : Object[] = [1, "a", null, 2.2, true]; // Object can contain everything
def e : Object[] = null; assert(e == []);
assert([] == null); // null is empty
assert(sizeof a == 5); // sequence length
assert(a == [5+5, 4*5, 60/2, 50-10, 10*5]); // embedded expressions
assert([1, [2, 3, []], [4, 5]] == [1, 2, 3, 4, 5]); // flattening (more)
assert([1..3] == [1, 2, 3]); // range
assert([1..6 step 2] == [1, 3, 5]); // range with step
assert([4..2 step -1] == [4, 3, 2]); // negative step
assert(reverse [1, 5, 10] == [10, 5, 1]); // reverse a sequence
assert(reverse [1..3] == [3..1 step -1]);
def a = [10, 20, 30, 40, 50];
assert(a[1] == 20); // read single element
assert(a[7] == 0); // default value if index does not exist
assert(a[1..3] == [20, 30, 40]); // slicing (inclusive)
assert(a[1..<3] == [20, 30]); // slicing (exclusive)
assert(a[1..] == [20, 30, 40, 50]); // end is optional (inclusive)
assert(a[1..<] == [20, 30, 40]); // end is optional (exclusive)
assert(a == [ a[0..1], a[2..] ]);
var a = ["a", "b", "c", "d"];
a[1] = "BBB"; assert(a == ["a", "BBB", "c", "d"]); // replace member
a[4] = "d"; assert(a == ["a", "BBB", "c", "d"]); // does nothing (index too large)
a[4] = ["d"]; // assigning a sequence not allowed
def b = ["a", "b", "c", "d"];
b[1..1] = ["b1", "b2", "b3"]; // replace slice
assert(b == ["a", "b1", "b2", "b3", "c", "d"]);
def c = ["a", "b", "c", "d"];
c[0..<2] = []; assert(c == ["c", "d"]); // delete slice
c[-1..-1] = ["a", "b"]; assert(c == ["c", "d"]); // does nothing
def d = ["c", "d"];
d[0..0] = ["a", "b", d[0]]; // better use insert statement
assert(d == ["a", "b", "c", "d"]);
def e = ["a", "b", "c", "d"];
e[4..4] = ["e"]; // append (better use insert statement)
assert(e == ["a", "b", "c", "d", "e"]);
def a = [12, -2, 0, 21, -100, 3];
assert(a[x | x >= 0] == [12, 0, 21, 3]); // select clause to filter sequences
assert(a[c | c < -10 or c > 10] == [12, 21, -100]);
assert(a[c | indexof c mod 2 == 0] == [12, 0, -100]); // indexof is the current index
var a = ["a", "b", "c"];
insert "d" into a; assert(a == ["a", "b", "c", "d"]); // appends elements
insert ["e", "f"] into a; assert(a == ["a", "b", "c", "d", "e", "f"]); // append sequence
var b = [1, 2, 3];
insert 34 before b[2]; assert(b == [1, 2, 34, 3]); // insert before
insert [-1, 0] before b[0]; assert(b == [-1, 0, 1, 2, 34, 3]);
var c = [1, 2, 3];
insert 34 after c[2]; assert(c == [1, 2, 3, 34]); // insert after
insert [22, 23] after c[0]; assert(c == [1, 22, 23, 2, 3, 34]);
var d = [1, 2, 3, 4, 5, 6];
delete d[1]; assert(d == [1, 3, 4, 5, 6]); // delete single element
delete d[1..3]; assert(d == [1, 6]); // delete slice
delete d; assert(d == []); // delete all elements
var e = [1, 3, 1, 4, 2, 2, 1];
delete 1 from e; assert(e == [3, 4, 2, 2]); // delete by value

