Skip to content

Dictionary Prototypes

Dictionary values expose key/value helpers.

let user = {
"name": "Martin",
"age": 19
}
println(user.keys())
println(user.values())

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())
MethodReturnsDescription
keys()[]KReturns all dictionary keys.
values()[]VReturns all dictionary values.
remove(key: K)voidRemoves a key from the dictionary.

Dictionaries implement internal __get__ and __set__, which power indexed access.

let user = {
"name": "Martin"
}
println(user["name"])
user["role"] = "admin"
println(user["role"])
let config = {
"host": "localhost",
"port": 3000
}
println(config.keys())
println(config.values())
let config = {
"host": "localhost",
"port": 3000
}
config.remove("host")
println(config.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"])