Statements
Statements execute program behavior. Top-level code is intentionally limited; loops run inside functions.
Syntax
Section titled “Syntax”x = 1y: num = x + 1xs = [1, 2, 3]xs[0] = 10
if y > 1: print(y)else: print(0)Semantics
Section titled “Semantics”Assignment binds a value to a name. An optional type annotation checks the value at runtime.
Subscript assignment is pure rebinding syntax for lists and dicts. Normal subscript assignment supports nested indexing. Slice assignment is not implemented.
xs = [1, 2, 3]xs[1] = 20
counts = {"a": 1}counts["b"] = 2
matrix = [[1, 2], [3, 4]]matrix[0][1] = 9Destructuring assigns values from a list or tuple to multiple names.
name, score = ("nilakan", 10)(first, rest) = [1, [2, 3]]The source value must have the same number of items as the target list. Empty destructuring is not supported. Parentheses are allowed around a destructuring target list.
Function call statements are allowed when the return value is intentionally discarded. They are also the only legal way to call an effectful procedure.
def observe(value: num) -> num: return value
observe(1)print(...) is an effectful builtin procedure. It may be called at top level, from a function, or
inside a commit loop, but it cannot be used where an expression value is required. A user-defined
function that calls print, directly or through another function, is treated as an effectful
procedure and is likewise callable only as a statement.
if, elif, and else select a branch using boolean guards. Branches may be indented blocks or
single-line blocks. Single-line blocks cannot contain nested block statements.
return ends a function and must return a value.
Constraints And Errors
Section titled “Constraints And Errors”return is illegal at top level. Top-level while and init are not supported; put commit loops
inside functions. Output produced during a commit-loop round is transactional: Nilakan publishes it
only if that round commits. See Commit Loops.
Primed destructuring is only legal inside a commit loop and only for state variables introduced by
init. A fallible right-hand side still needs an error handler:
def take_first(values: list[num]) -> list[num]: init: rest = values done = False while not done: item, rest' = rest.pop(0) catch (0, rest) done' = True return restPrimed subscript assignment supports one index only. Nested primed subscript assignment is not implemented.
Examples
Section titled “Examples”def choose(flag: bool) -> str: result = "yes" if flag else "no" return result
print(choose(True))