Dodo doc > Syntax > Literal Values > Collection Literals


Collection literals

List literals

A list is an ordered collection of items. Items of the list are enclosed in square brackets. Collection literals can be used as items. If the item contains a dodo-style block it must be put inside brackets.

Examples:

[1, 2, 3, 6, 12]
[apple, orange, pear]
Rationale: square brackets are reserved for collections, which gives them a unified syntax. The restriction on dodo blocks in list items is necessary as the colon is used in maps.

Set literals

A set is an unordered collection of distinct items. The items of a set literal are enclosed in square brackets and each is prefixed with a colon. There are restrictions on the type of the items in a set.

Examples:

[:apple, :orange, :pear]
[:"100km", :"Jane", :"red"]
Rationale: the initial colon clearly distinguishes set elements from list or map items while the square brackets show that a set is also a collection.

Map literals

A map is an unordered collection of key, value pairs. The entries are enclosed in square brackets and a key is separated from the associated value with a colon. Collection literals can be used as values. If the key contains a dodo-style block is must be put inside brackets. There are restrictions on the type of map keys.

Examples:

[apple: [gala, cox], orange: [navel], pear: [conference, comice]]
["Ok": 1, "Cancel": 2]
Rationale: a dodo-style block starts with a colon, hence it cannot appear in the key without brackets. Keys are used to retrieve values from the map so they need to be located efficiently. That puts restrictions on their type.

^ 2.4.4. Enum Values

v 2.4.6. Tuples