What Beans is
Beans is a small, general-purpose programming language with explicit types, predictable ownership, and direct systems access.
It supports standalone functions and closures, structs and enums, and classes with interfaces and inheritance. Structs copy by value; classes have reference semantics. You can write a complete program with functions, without defining a class.
Source files end in .b.
Types, arithmetic, and errors
Section titled “Types, arithmetic, and errors”- Mandatory explicit types. Declarations state their types.
- Exact
decimalarithmetic. Base-10 arithmetic gives19.99 * 3as59.97exactly. - No null and no exceptions. Missing values use
Option<T>; failures useResult<T>.
Memory and systems access
Section titled “Memory and systems access”- Sized integers like
i32andu64, and value types (struct,union). - An
unsafelayer with raw memory and C interop. - Automatic memory management. Memory uses automatic reference counting with a cycle collector, rather than a tracing garbage collector.
One tool: beansc
Section titled “One tool: beansc”There is a single command, beansc, and it is the whole toolchain:
- a type checker that verifies your program,
- a reference interpreter that runs it with no build step,
- a native LLVM backend that compiles it to a real binary,
- a package manager (
beansc pot), - a language server (LSP) for editors, and
- a debugger (DAP).
beansc is self-hosted: the Beans compiler is written in Beans and compiles
itself.
A tiny example
Section titled “A tiny example”Here is a complete Beans program. Save it as hello.b.
import std.io
fn main() { let name: string = "beans" io.println("hello from {name}")}{name} inside the string is interpolation: it prints the value of name. Run
it with:
beansc run hello.bhello from beansNext, read the language philosophy for the rules behind these choices, or install Beans and run your first program.