Language
Dicts & Sets
Dictionaries are typed key-value stores with ordered insertion. Sets are unordered collections of unique values.
Dictionaries
Every dictionary has a type annotation <key_type, value_type>. Use any for the value type when the values are mixed:
// Typed dict — enforces types
let prices <string, int> = ({"apple", 2}, {"banana", 1})
// Mixed values — use any
let config <string, any> = ({"debug", true}, {"port", 8080})
// Empty dict
let cache <string, int> = ()Reading values
out prices["apple"] // → 2 out config["debug"] // → true // Missing key in an any-value dict returns null let missing = config["nope"] ?? "default" out missing // → default
Note: Accessing a missing key in a typed dict (where value type ≠
any) is a runtime error. In an any-value dict, it returns null — use ?? for a fallback.Adding and updating
let scores <string, int> = ({"Alice", 90}, {"Bob", 75})
// Method syntax
scores.Add({"Carol", 88}) // add new key
scores.Add({"Bob", 80}) // overwrite existing key
// Index assignment (same as Add)
scores["Dave"] = 95
scores["Alice"] = 100
out scores // → {Alice: 100, Bob: 80, Carol: 88, Dave: 95}Removing entries
scores.Remove("Bob") // remove one key
scores.RemoveAll() // clear everything
scores.clear() // alias for RemoveAllIterating
let scores <string, int> = ({"Alice", 90}, {"Bob", 75}, {"Carol", 88})
// Get all keys
let names = scores.toList()
out names // → [Alice, Bob, Carol]
// Get all key-value pairs as a 2D array
let pairs = scores.toArray()
out pairs // → [[Alice, 90], [Bob, 75], [Carol, 88]]
// Filter using the pairs
let top = pairs.filter(pair => pair[1] >= 85)
out top // → [[Alice, 90], [Carol, 88]]Sets
A Set is an unordered collection of unique values — duplicates are silently ignored:
let s = new Set()
let s2 = new Set([1, 2, 3, 2, 1]) // duplicates removed
out s2 // → Set{1, 2, 3}Working with sets
let a = new Set([1, 2, 3, 4]) out a.size // → 4 out a.has(2) // → true out a.has(99) // → false a.add(5) a.delete(1) out a.toArray() // → [2, 3, 4, 5] (order may vary)
Set operations
let a = new Set([1, 2, 3, 4])
let b = new Set([3, 4, 5, 6])
out a.union(b) // → Set{1, 2, 3, 4, 5, 6}
out a.intersection(b) // → Set{3, 4}
// Practical: deduplicate an array
let dupes = [1, 2, 2, 3, 3, 3]
let unique = new Set(dupes).toArray()
out unique // → [1, 2, 3]