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

#### 6.2.10 Lists

Lists are collections of arbitrary values or variables of arbitrary classes and data types. Any combination of data classes and types can be put in a list. Each element of a list can have a name tag associated with it, unlike compact lists (Compact Lists).

One specifies a list by listing its elements, separated by commas, and enclosed in curly braces. Each element of a list consists of either just a value, or of a name tag followed by a colon and the value. For instance,

```a = { NAME: 'Alpha Centauri, DISTANCE: 4.3, UNIT: 'lightyears' }
b = { NUMBER: 17, 3.2 }
```

defines a list `a` with name tags associated with all values, and a list `b` with a name tag only for the first element. Values inside a list need not have an associated name tag, but lists with no name tags at all associated with their elements are automatically transformed into `list`s.

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

For instance,

```q = [ a, b ]
q = { NAME: 'Alpha Centauri, DISTANCE: 4.3, UNIT: 'lightyears',
NUMBER: 17, 3.2 }
```

are equivalent definitions of `q`, whereas ```u = { FIRST: a, b }``` defines a list `u` with two elements which are themselves lists, too.

One can refer to a particular element of a list by subscript, as for compact lists, or by name tag. For example, `z(1)` and `z.DISTANCE` both refer to the number 4.3. One can extract more than one element from a list using subscripts, just as for compact lists and arrays (Arrays).

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

Lists were a late addition to LUX. By the time they were added, two LUX read-only constants `#r.d` and `#d.r` (#r.d, #d.r) were already in widespread use with names that contained a period. Disallowing these two names would force all programs that already contained them to be changed, so these names are retained as the only exception to the rule that two text strings separated by a period indicate a member of a list. Their use is discouraged, however, in favor of `#deg` and `#rad` (#deg, #rad) which serve the same purpose but do not contain periods.

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