Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Name values

Use = to create a binding. Plenty infers the type of a local value, so you usually do not need an annotation:

def main() -> Result[(), IoError | OverflowError[i64]]:
    # Comments begin with a hash.
    price = 20
    quantity = 3
    total = price * quantity
    print(total)?
    Ok(())
60

To see inferred types without writing annotations, enable your editor’s inlay hints. For example, the Plenty language server can show : i64 after price, quantity, and total. These labels are only displayed in the editor; they are not added to your source file. Hover also shows a binding’s type.

Bindings are immutable by default:

def main() -> ():
    score = 10
    score = 11
`score` is immutable; declare it with `mut`

Use mut when a value needs to change. Write it once, at the declaration:

def main() -> Result[(), IoError | OverflowError[i64]]:
    mut score: i64 = 10
    score += 5
    print(score)?
    Ok(())
15

A mutable binding keeps its original type. score: i64 states the type explicitly; without the annotation, this integer literal also infers i64.

score += 5 adds to the current score. Numeric values also support -=, *=, /=, //=, and %=. Use //= for integer division and /= for float division; %= requires integers. These updates require an existing writable destination and keep its type. Strings and collections use their explicit operations.