Files
rexlang/examples/basics/maps.dino
T
Your NameandClaude Sonnet 5.5 eaf9567a36 Dino compiler: language, formatter, language server, docs, editor support
Compiler in Rust (lexer, parser, checker, C codegen), maps, chars,
dino fmt, dino lsp (diagnostics, formatting, outline, definition,
hover, completion, signature help), docs, examples, VS Code/Vim files.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 23:46:12 +01:00

49 lines
1.2 KiB
Plaintext

struct Team {
name: string
scores: map[string, int]
}
func total(m: map[string, int]): int {
var sum = 0
for k, v in m { sum += v }
return sum
}
func main() {
var ages = {"alice": 30, "bob": 25}
ages["carol"] = 41
ages["bob"] = 26
print(ages["bob"], ages.len(), ages.has("dave"), ages)
print(ages.get("alice"), ages.get("zed"), ages.get_or("zed", -1))
var counts: map[string, int] = {}
for w in "a b a c b a".split(" ") {
counts[w] += 1
}
print(counts)
for k, v in counts { print(k, "->", v) }
for k in counts.keys() { print("key", k) }
print(counts.values(), total(counts))
counts.remove("b")
print(counts, counts.len())
var copy = counts
copy["z"] = 9
print(counts.len(), copy.len())
var nums = map[int, []string]{}
nums[1] = ["x", "y"]
nums[2] = []
nums[1].push("z")
print(nums)
var t = Team{name: "red", scores: {"a": 1}}
t.scores["b"] = 2
var t2 = t
t2.scores["c"] = 3
print(t.scores.len(), t2.scores.len())
var big = map[int, int]{}
for i in 0..2000 { big[i * 7] = i }
var s = 0
for i in 0..2000 { s += big[i * 7] }
print(s, big.len())
for i in 0..1000 { big.remove(i * 7) }
print(big.len())
}