Chapter 4. Collection Literals

Table of Contents
List literal
Map literal

List literal

List literal in PPL

A list literal consists of an enumeration of arbitrary complex expressions, separated by a comma, and delimited by square brackets.

The type of elements in the list is inferred by the compiler, but can be specified explicitly if desired.

Example:

const list = ["A", "B", "c".to_upper_case]

assert list.size   =v 3
assert list.first  =v "A"
assert list.get(2) =v "B"
assert list.last   =v "C"

// The type can be specified explicitly:
const yes_no_list list<yes_no> = [yes, no, yes, yes]

Map literal

Map literal in PPL

A map literal consists of an enumeration of key:value pairs, separated by a comma, and delimited by square brackets.

The types of the keys and the values in the map are inferred by the compiler, but can be specified explicitly if desired.

Example:

const map = [ "A": 1, "B": 2, "c".to_upper_case: 1+1+1 ]

assert map.size =v 3
assert map.get("C") =v 3

// The type can be specified explicitly:
const map2 map<key:string, value:yes_no> = [ "A": yes, "B": no, "C": yes ]