Quickstart¶
Hello, world¶
Create hello.kod:
Build and run:
uv run kod run hello.kod does both in one step.
A real program¶
func greet(anon name: str) -> none {
print(f"Hello, {name}!")
}
func main() -> int64 {
let names: [str] = ["Alice", "Bob", "Carol"]
for name in names {
greet(name)
}
return 0
}
Variables¶
Bindings are declared with let and are immutable — the name can't be
reassigned. A type annotation is usually required:
For a binding you intend to reassign, use mut:
mut count: int64 = 0
count = count + 1 // ok
let limit: int64 = 10
limit = 20 // error: cannot reassign immutable binding `limit`
A test file¶
// arithmetic_test.kod
test "addition" {
assert 2 + 2 == 4
}
test "subtraction" {
assert 10 - 3 == 7
}
Next steps¶
- Types — the full type system
- Functions — declaration, parameters, return types
- Control flow —
if,for,match - Testing — the
testandassertsyntax