Dictionary Prototypes
Dictionary values expose key/value helpers.
let user = { "name": "Martin", "age": 19}
println(user.keys())println(user.values())Current Literal Limitation
Section titled “Current Literal Limitation”Prototype calls currently work reliably on values stored in variables.
let s = "string"
println(s.length())Calling prototype methods directly on literals is currently limited by AST/parser behavior.
// Currently may not work:println("string".length())Prefer assigning the literal to a variable first.
let text = "string"
println(text.length())Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
keys() | []K | Returns all dictionary keys. |
values() | []V | Returns all dictionary values. |
remove(key: K) | void | Removes a key from the dictionary. |
Indexed Access
Section titled “Indexed Access”Dictionaries implement internal __get__ and __set__, which power indexed access.
let user = { "name": "Martin"}
println(user["name"])
user["role"] = "admin"
println(user["role"])Keys and Values
Section titled “Keys and Values”let config = { "host": "localhost", "port": 3000}
println(config.keys())println(config.values())Removing Keys
Section titled “Removing Keys”let config = { "host": "localhost", "port": 3000}
config.remove("host")
println(config.keys())Missing Keys
Section titled “Missing Keys”If a key does not exist, direct access can throw an error.
let config = { "port": 3000}
// This can error if "host" does not exist:println(config["host"])