Next: , Previous: Properties, Up: Marsyas Expression Syntax Sequences (Lists)

Sequence types are those data types that have a sequence of elements. Falling into this category are lists and strings not natural or real numbers.

Lists are denoted using the square brackets as in [ 1, 2, 3 ]. Lists can contain other lists as in [ [1,2], [3,4] ]. However, all elements of a list must be of the same type. This [ 1, '2'] and this [ 1, [ 2, 3 ] ] are not valid lists.


There are four different iterators for working with sequence types: map, iter, for, rfor. There are subtle differences.

Element Access

Elements of sequences may be accessed using the standard array notation as in a<<[1,2,3], one<<a[0], three<<a[2]. Note that the first element is position 0. Don't let me catch you using an index that's too big.


Slices are portions of sequences. A range takes two positions in the list - start position (included) and end position (not included) separated by a colon [start:end]. If the start position is left out then the first element is assumed. If the last element is left out then the end is assumed. The start and end positions may be adjusted to avoid errors, ie negative start becomes the beginning of the list.

We can take the head and tail of a list using slices: a<<[1,2,3], hd<<a[0], tl<<a[1:].

Concatenation, Joining

Sequences may be joined using the concatentation operator otherwise known as +. [1,2,3]+[4] joins the two lists into [1,2,3,4].