Builtins
A builtin is a type or function provided by the compiler without an import.
Examples include int, string, List, Option, and panic.
This page lists every builtin and links to a page that explains it in full.
Two layers
Section titled “Two layers”Beans builds its builtins in two ways. You do not need to think about this while you write code, but it helps to know it once.
- Some builtins are implemented by the C runtime and reached through a fixed table (the
“runtime ABI”). These are
string,Bytes,File,MMap, and thestd.*modules that talk to the operating system. You can see the table atsrc/expression.b. - The rest are written into the compiler’s own type checker and turned into
machine code by the code generator. These are the generic types (
List,Map,Box,Atomic,RawPtr,Slice, SIMD) and compile-time helpers likesize_of. You can see the checker atsrc/expression.b.
The current release reports runtime ABI 23, compiler 0.1.53, and the
candidate language contract 1.0. Installed release output is shown under
Verify the install.
Error handling is builtin
Section titled “Error handling is builtin”Beans has no null and no exceptions. Instead it gives you three builtin types for “maybe” and “failed” answers, and you will see them all over this reference:
Option<T>: a value that may be missing.Result<T, E>: a value or an error.Error: the standard error class.
These, and the collection types like List and Map, are all builtin. Read
Option, Result, and Error for the full story.
All builtin pages
Section titled “All builtin pages”| Page | What it covers |
|---|---|
| Primitive types | unit, bool, the integer and float types, byte, string |
| Numbers and decimal | number rules, casts with as, and exact decimal math |
| string | the string type and every method on it |
| Bytes | the growable byte buffer Bytes |
| Collections | List, Map, and OrderedMap |
| Option, Result, and Error | Option, Result, Error, some/none/ok/err, the ? operator |
| Ownership handles | Box, Arena, Shared, Weak, Mutex, Channel, Thread, Brew, TaskGroup, Gate, AtomicInt |
| Atomics | Atomic<T> and MemoryOrder |
| Files and mapping | File, Dir, MMap |
| SIMD, arrays, and pointers | Simd{N}{elem}, [T; N], Slice<T>, RawPtr<T> |
| Prelude functions | panic, size_of/align_of/offset_of, printing |
See also
Section titled “See also”- The language guide explains how types, errors, memory, and the rest fit together.
- The standard library reference covers the modules you
import with
import std.*.