Skip to content
All guides

learn

Errors you can see

Overdraft is not a crash. It is a value the caller must handle.

enum LedgerErr {
    Insufficient,
}

fn withdraw(balance: int, amount: int) -> int {
    if amount > balance {
        raise "insufficient"
    }
    balance - amount
}

raise writes the message to stderr and returns empty (0 for ints). ? forwards that empty value. ?? supplies a default:

fn run_day(balance: int) -> int {
    after = withdraw(balance, 1200)?
    after
}

fn main() {
    left = withdraw(500, 900) ?? 0
    println(left)
}

Do not match Ok / Err — the guest does not tag those. match Color.Red on a declared enum works. ! is boolean not, not unwrap.

The ledger is now a small language tour you can keep on disk. Next: modules: then split this CLI and serve it.