Experimental documentation — Work in progress
This page has not completed the documentation audit. Current documentation version: experimental.
Statements
Statements perform actions. Ordinary statements are newline-terminated rather than semicolon-terminated. The tokenizer emits logical newline tokens while suppressing continuation newlines in known contexts.
Statements include declarations, assignments, expression statements,
if/else, match/case, for/in, while, until,
break, continue, return, yield, and exception constructs.
The language supports newline-separated blocks, let declarations,
ordinary = and compound +=, -=, *=, /=, %=, and ^= assignment
statements, expression statements inside blocks,
if/else including else if chains, for name in expression, while, and
until loops, unlabeled break and continue, and bare or value-bearing
return and yield. Control-flow bodies may be braced blocks or exactly one
statement on the same logical line as the header. The parser also accepts
match expression with one or more case branches. An optional case else
must be unique and last.
Empty blocks are valid. break and continue outside a loop are syntax errors.
A block brace is recognized from its statement position, while {...} in an
expression remains a dictionary literal.
Exception statements use hope for the protected block, expression-shaped
unless handler patterns, optional final finally cleanup, and scream
expression to raise a value. A hope requires at least one handler or cleanup
clause. Handlers are tried in source order, unmatched exceptions propagate
outward, and finally runs during both normal and exceptional exits. See
Exceptions.
The selected root file is the executable program. Its declarations and
executable statements run in source order, so a small program needs no
main function:
Root-level mutable bindings are visible to functions in that file. Imported
modules may contain declarations but not executable top-level statements;
importing a module never runs an implicit script. Normal completion exits with
status 0. Call exit(code) to end immediately with a status from 0 to
255; finally cleanup runs before the process exits. A final expression is
neither printed nor used as an exit code.
return remains function-only, and a function named main is ordinary.
Compound assignment is statement-only, like ordinary = reassignment. Its
target must be assignable, and the result must convert losslessly back into the
target's type.
Parallel reassignment uses one = with comma-separated variable names and
the same number of values:
Every right-hand expression is evaluated from left to right before any target
changes. Then the variables are assigned from left to right, so the example
leaves a as 1 and b as 1. Targets must be distinct, mutable variable
names; fields, indexes, compound operators, and mismatched list lengths are
not supported in this form. This is reassignment, not a declaration or tuple
expression.
Parallel let declares new mutable names with matching initializers:
All initializer expressions run before any new name is introduced. A group
requires exactly one value per name; individual names may carry type
annotations. Unannotated integer variables default to Int64. The loop shows
two other independent rules: postfix i++ yields the old value, and a
single-statement while body can omit braces when it stays on the same line.
unless is reserved for exception handling in Sagan; it is not an inverse
conditional spelling.
yield expression and bare yield are syntactically valid inside function
bodies, but generators do not execute yet. Generator typing and suspension are
deferred.
Enum and optional patterns bind typed payload names, and covering every enum
case is recognized as exhaustive. Non-Void functions must return on every
guaranteed path, and code after a guaranteed return is rejected as unreachable.
Custom iteration protocols, broader destructuring patterns, and generators are
deferred.