Arrays, dictionaries, and hybrid tables
Start with an array for a sequence, a dictionary for named or keyed values, and a hybrid table when you need both kinds of access.
Arrays
Arrays are zero-indexed. Use '[]' and access an item by position.
scores = [8, 12]
print(scores[0])
Output
8
Dictionaries
Use braces and named keys to describe a record.
player = {
name = 'Ada'
health = 100
}
Read a field with dot syntax.
print(player.name)
Output
Ada
Assign to a field to update it.
player.health -= 10
print(player.health)
Output
90
Hybrid collections
An Atom table can include positional and keyed entries. Iteration visits the dense sequence first, then keyed entries in insertion order.
Arrays, dictionaries and hybrid tables share a runtime representation with a dense sequence and an ordered associative part. Square brackets construct arrays. Braces containing only named or computed keys construct dictionaries. Braces with positional entries or a spread construct hybrid tables. Identifier field keys become strings. A computed key uses [key] followed by =.
Arrays index from zero. Assignment replaces an existing array element. Add appends an item or inserts one at an explicit index, and removal shifts subsequent items. Dictionary lookup returns null for a missing key. The collection.contains operation distinguishes a missing key from a stored null.
Hybrid tables assign sequential positions from zero. Setting the next dense index extends the sequence. Higher integer indices are associative. If an append reaches an existing associative index, the append replaces that entry. Iteration visits the dense sequence first, then the associative entries in insertion order. Replacing a key preserves its position. Count includes both parts. Collection equality uses reference identity.