[Contents] · [Home] · [Mail]

SALIERI Language - list (Object Type)

Objects of type list represent heterogeneous list structures the components of which are arbitrary objects (of possibly different types); list structures can be arbitrarily nested (lists of lists, etc.) - because of the heterogenous list concept this allows the usage of nested lists to represent arbitrary tree structures.

There are two ways to construct lists from gven elements: The constructor LIST(el1,el2,...) which returns a list (el1,el2,...); and the constructor LISTINIT(n,el) which returns a list of length n where each element is a copy of el. Here, el,el1,el2,... can be arbitrary expressions; the list elements are set to the values of these when constructing the list object. A third constructor consList can be used to incrementally built lists.

The empty list can also be represented by (), and for lists with two or more elements, LIST(el1,el2,...) can be abbreviated as (el1,el2,...). This does not work for one element lists, since according to the general definition of expressions, (el) is equivalent to el.

The basic operations on lists are element access (@), concatenation (+), substring extraction (infix), length (#), and substring location (posNext). These operations are analogously defined on note sequences and strings. Element positions within lists are numbered 1,2,3, and so on.

Element access has precedence over the length operator, i.e., #ls@n is equivalent to #(ls@n). List elements can be used within assignments just like any other objects; in particular, they can be reassigned by means of a statement of the form: ls@n := expression. There are builtin functions getList and putList, which can also be used for accessing and reassigning list elements, but the usage of these is considered obsolete and should be avoided.

Equality operators (= and !=) can be applied to lists; two lists are equal if and only if they have the same number of elements, and each two corresponding elements have the same type and equal values.

> ls := (42, TRUE, [c1/4 d# c/2])
> ls
Results= LIST(42, TRUE, [c1/4 d# c/2])
> ls@2
Results= TRUE
> infix(ls,1,2) + LIST(LISTINIT(3,[e&1/4]))
Result= LIST(42, TRUE, LIST([e&1/4], [e&1/4], [e&1/4]))
> ls@3 := ();
> ls
Result= LIST(42, TRUE, LIST())
> (1,2,3)
Results= LIST(1,2,3)
> (34)
Result= 34

See also: LIST, LISTINIT, consList, @, getList, putList, +, length (#), infix, posNext, sequence (Object Type), string (Object Type), Operator "=", Operator "!=", Predefined Functions, Operators and Expressions.

[Contents] · [Home] · [Mail]
© sic!systems, page frame designed by hh; this page has been automatically generated from the SALIERI Documentation Database.