Next: , Previous: , Up: Data Classes   [Contents][Index]

6.2.8 Compact Lists of Variables

A compact list (clist) is a collection of arbitrary values or variables of arbitrary classes and data types. Any combination of data classes and types can be put in a compact list. A compact list is a restricted version of a full list (Lists). Any list without keywords is automatically transformed into a compact list. A compact list is created by listing the elements, separated by commas and enclosed in curly braces. For example,

x = { [22, 12, 3.0], 'computers can be fun', (6:23) }
y = { 'Alpha Centauri', 4.3, 'lightyears' }

defines two compact lists. List x combines a float array (Arrays), a string (Strings), and a range expression (Ranges), and list y combines a string, a scalar (Scalars), and another string.

You can specify a compact list without any elements, as {}.

One can combine different compact lists and other elements into a single compact list, or into a compact list of lists and other things. Concatenation using curly braces ({}) preserves the structure of all concatenated elements, whereas concatenation using square brackets ([]) removes the outermost grouping from compact lists, similar to how array concatenation works.

For instance,

q = [ x, y ]
q = { [22, 12, 3.0], 'computers can be fun', (6:23), 'Alpha Centauri',
       4.3, 'lightyears' }

are equivalent definitions of a clist with all elements of x and all elements of y as its elements. In contrast to this,

u = { x, y }

defines a compact list with just two elements: The first element is compact list x, and the second element is compact list y.

One refers to a particular element of a compact list by subscript. For example, q(1), and u(0)(1) both refer to the string 'computers can be fun'. One can extract more than one element from a compact list using subscripts, just as for arrays (Arrays). The subscripts may be scalars, ranges, or arrays of indices.

Lists can be used to specify arbitrary number of subscripts to functions or expressions. Lists of Subscripts.

Next: , Previous: , Up: Data Classes   [Contents][Index]