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

koto-calc CLI

koto-calc provides a command-line interface for running .koto scripts and an interactive REPL.

Installation

Build from source with the Rust toolchain (see rustup.sh for installation instructions):

cargo build --release
cargo install --path .

This provides the koto_calc command.

Usage

koto_calc [FLAGS] [script] [<args>...]

Flags

FlagDescription
-e, --evalEvaluate the argument as a script string instead of loading from disk
-i, --show_instructionsShow compiled instructions annotated with source lines
-b, --show_bytecodeShow the script’s compiled bytecode
-t, --testsRun the script’s tests before running the script
-T, --import_testsRun the script’s tests, plus tests in imported modules
-f, --formatFormat the input (from script path or stdin)
-c, --config PATHConfig file to load
-C, --print_configPrint the default config
-v, --versionPrint version information
-h, --helpPrint help information

Arguments

Arguments following the script name are available to the script via os.args.

Running Scripts

# Run a script from a file
koto_calc examples/fibonacci.koto

# Evaluate an expression directly
koto_calc -e "print (1..10).sum()"
# Output: 55

# Run tests in a script
koto_calc -t tests/example.koto

# Pass arguments to the script
koto_calc print_args.koto a b c

Using the REPL

Running koto_calc without arguments starts the REPL:

> koto_calc
Welcome to Koto

» 1 + 1
➝ 2

» 'hello!'
➝ hello!

» size [1, 2, 3]
➝ 3

The help command in the REPL provides access to the language guide and core library reference:

» help number
Numbers and Arithmetic
======================
...