The Crow Programming Language

Maps Are Dictionaries

A map is a lookup table: string keys, values of one type. Build one with the map[...] constructor; read with dot or bracket; set returns an updated copy:

1
2
3
4
5
6
7
8
scores = map[alice = 10, bob = 7]
log[scores.alice]
log[scores['bob']]

s2 = set[scores, 'carol', 9]
log[s2]
log[keys[s2]]
log['alice' in scores]

expected output — from the book, verified by crow test --book

10
7
[alice = 10, bob = 7, carol = 9]
['alice', 'bob', 'carol']
true

The one-type rule is enforced — a map of ints won't accept a string. If you're tempted to mix types under named keys, what you want is not a map. It's the next section.