Syntax and control flow
Read bindings, indentation, expressions, comments, branches and loops.
Indent exactly four spaces per block level. Tabs at the start of an indented line are rejected. Blank lines and full-line # or // comments are skipped. A # starts an inline comment outside double-quoted text. Use name = value for a mutable binding and fixed name = value for a fixed binding.
Use when and otherwise for branches. repeat iterates over lists and ascending end-exclusive ranges. Task blocks use task, optional gives and give for returned values.
advanced
examples/advanced/src/main.zbl · v0.5.0-preview.5 · interpreter, bytecode
shape Account:
name: text
balance: i64
task multiply(a: i64, b: i64) gives i64:
give a * b
task safe_divide(a: i64, b: i64) gives i64:
attempt:
give a / b
otherwise problem:
show problem.kind
give 0
fixed account = Account("Ada", 120)
items: List[i64] = []
repeat i in 1..4:
items = append(items, multiply(i, 2))
counts: Map[text, i64] = {"items": len(items)}
when account.balance > counts["items"]:
show account.name
otherwise:
show "empty"
show items[2]
show safe_divide(10, 0)
task test_collections():
assert({"a": 3}["a"] == [3][0])
Ada
6
DivisionByZero
0