Bundt Scripting Reference · Bundt Scripting Language version 1.0.1.0

Collections

A collection is an organized group of values. For example, [1, 2, 3] is a sequence of numbers, which is one kind of collection.

By "organized" we mean that the items in a collection are ordered, and sometimes, depending on the kid of collection, they may be also indexed.

Details

There are two kinds of collections:

  • Sequences are simple lists of ordered items.
  • Dictionaries are lists of ordered and indexed items.
Sequences

A sequence is expressed as a comma-separated list of items enclosed in square brackets, for example:

  • [1, 2, 3] is a sequence of numbers with three items.
  • ["Hello", "World"] is a sequence of texts with two items.

All items in a sequence must be of the same type. As a result, the sequence as a whole has a type Sequence<T>, where T is the type of the member items. For example, the sequence [1, 2, 3] is of type Sequence<Number>.

Dictionaries

A dictionary is expressed as a comma-separated list of items enclosed in square brackets. Each item is a pair composed by a key and a value, separated by a colon. Keys are always identifiers. For example:

  • [One: 1, Two: 2, Three: 3] is a dictionary of numbers with three items.
  • [A: "Hello", B: "World"] is a dictionary of texts with two items.

All items in a dictionary must have values of the same type. As a result, the dictionary as a whole has a type Dictionary<T>, where T is the type of member item values. For example, the dictionary [One: 1, Two: 2, Three: 3] is of type Dictionary<Number>.

Each item in a dictionary is indexed by the preceding identifier. For example, in the dictionary [One: 1, Two: 2, Three: 3], the value 2 is indexed by identifier Two. This is especially important when using dictionaries to express multilingual data.

Expressions in collections

Note that the values contained in collections don't need to be literals, and may include expressions. For example, the sequence [12 / 3, (6 - 5) / 4] yields a result of [4, 0.25].

Nested collections

You can even nest collections inside other collections. For example, [[12 / 3, (6 - 5) / 4], [-3 / 2]] is a sequence of two sequences of numbers. Its type is Sequence<Sequence<Number>>.

You can also combine kinds of collections. For example, [First: [12 / 3, (6 - 5) / 4], Second: [-3 / 2]] is a dictionary of two sequences of numbers. Its type is Dictionary<Sequence<Number>>.

See Also


Contents distributed under a Creative Commons Attribution 4.0 International License · About · Terms of Use · Contact Us · last updated on 08 October 2020