Implemented · v0.5.0-preview.5

Lists and maps

Work with List[T], Map[text, T], indexing and value semantics.

Lists contain elements of a common type. Maps use text keys. Annotate empty collections so the checker can determine the element type. Use append and put to return updated collection values.

Index and key lookups are checked. The native subset supports nested immutable values. Packed mutable byte buffers remain unsupported.

advanced

examples/advanced/src/main.zbl · v0.5.0-preview.5 · interpreter, bytecode

ZBL source
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])
Recorded output
Ada
6
DivisionByZero
0