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

Command-line arguments

args() returns Result[list[str], IoError]. Index zero is the executable’s invocation name, followed by the supplied arguments. Pass arguments to a compiled binary, for example ./program first "two words"; quoted spaces remain within one argument. Each call creates an independent list and reports allocation or UTF-8 errors.

def count_arguments() -> Result[bool, IoError]:
    values = args()?
    Ok(len(values) >= 1)

def main() -> Result[(), AllocError | IoError]:
    print(count_arguments()?)?
    Ok(())
True