Collections

Skip to end of metadata
Go to start of metadata

Mantra has built-in list and dict collections and associated literals:

Note that "=" is overloaded (means assignment also). It is unambiguous, however.

The array index operator has been overloaded for index lists and dicts:

Indexes start at 0 for lists.

For dict, of course, a[x] invokes the a.get(x) method.

Lists and dicts grow to include new members. If index 42 does not exist in a list, the list grows to be large enough so that the following does not cause a runtime exception:

The same is true for dicts:

Sample:

Naturally, lists and dicts and sets can all be nested, which also highlights that lists are heterogenous.

OrderedDict is a dict where the order of addition is remember.

The range operator ".." yields an interval that can be used to select a contiguous subset of a list yielding a stream object:

without copying the values. As a special case, sets may be used as list or dict indices to indicate a noncontiguous set of elements:

Tree example:

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.