abacus

Crates.ioabacus
lib.rsabacus
version0.1.6
created_at2025-11-06 09:50:59.314563+00
updated_at2026-01-20 06:47:48.431271+00
descriptionThe mathemagical programming language
homepagehttps://github.com/cyanboy/abacus
repositoryhttps://github.com/cyanboy/abacus
max_upload_size
id1919374
size303,496
Mathias Rørvik (cyanboy)

documentation

https://docs.rs/abacus

README

Abacus

ci Crates.io Version Documentation

Abacus is a experimental, interpreted functional programming language with a pleasant REPL

Highlights

  • Persistent REPL environment with history and an ANSI-colored prompt.
  • 64-bit integers, double-precision floats, and booleans with straightforward formatting.
  • Arithmetic, comparison, logical, and bitwise operators with predictable precedence.
  • Pattern-matched function arms: mix literals and identifiers and the most specific match runs.
  • Helpful diagnostics that underline exactly where evaluation failed.

repl

Install

Cargo

cargo install abacus

Try It

Usage

The Abacus calculator REPL and runner

Usage: abc [OPTIONS] [FILE]

Arguments:
  [FILE]  Execute the given Abacus source file

Options:
  -e, --expr <EXPR>           Evaluate a single expression and exit
      --no-color              Disable ANSI color output
      --recursion-limit <N>   Maximum recursion depth (default: 1000)
      --completions <SHELL>   Generate shell completions [bash, zsh, fish, powershell]
  -h, --help                  Print help
  -V, --version               Print version
  • Start the interactive REPL: abc
  • Evaluate a single expression and print the result: abc -e "2 + 2"
  • Execute a source file (runs each line in order, sharing the same environment): abc path/to/program.abc
  • Disable ANSI colors for scripts or terminals that do not support them: add --no-color (e.g. abc --no-color -e "1/3")
  • Color is also controlled by common environment variables: NO_COLOR disables color, CLICOLOR_FORCE=1 forces it, and CLICOLOR=0 disables it unless forced. Color is off when stdout is not a TTY unless forced.
  • Equality is type-strict: ints and floats cross-compare, but comparing booleans to numbers raises a type error instead of silently returning false.
  • Function calls have a recursion safeguard (default limit 1000, configurable via --recursion-limit or ABACUS_MAX_CALL_DEPTH); unbounded recursion (e.g., inf(n) = n * inf(n)) will eventually raise a recursion-limit diagnostic instead of looping forever.

REPL sessions retain history, coloring, and diagnostic output between entries:

[0x00]: rate = 0.0825
[0x01]: with_tax(amount) = amount * (1 + rate)
[0x02]: with_tax(24.99)
[0x02]: 27.05475
[0x03]: fib(0) = 0
[0x04]: fib(1) = 1
[0x05]: fib(n) = fib(n-1) + fib(n-2)
[0x06]: fib(10)
[0x06]: 55
[0x07]: odd(n) = n % 2 == 1
[0x08]: odd(41)
[0x08]: true

Build From Source

cargo build

Shell Completions

Generate shell completions for your shell:

# Bash
abc --completions bash > ~/.local/share/bash-completion/completions/abc

# Zsh
abc --completions zsh > ~/.zfunc/_abc

# Fish
abc --completions fish > ~/.config/fish/completions/abc.fish

# PowerShell
abc --completions powershell > abc.ps1

Limitations

  • Mixed integer and float arithmetic promotes integers to floats. Integers outside the range 2^53 may lose precision in the conversion.

License

This project is licensed under the MIT License.

Commit count: 91

cargo fmt