Documentation
Bop language guide

Overview

Standard Library — overview🔗

bop-std ships a small set of modules written in Bop itself. They live under the std.* namespace and are resolved by the default host (StandardHost in bop-sys) — any host that defers to StandardHost::resolve_module picks them up for free.

The stdlib is deliberately thin. Core math and Result operations are methods on values ((-5).abs(), (9).sqrt(), r.unwrap_or(0), r.map(f)) — they don’t need a module. The stdlib covers what’s left: constants, higher-order helpers on arrays, data-structure types, string formatting, JSON, test assertions.

Modules🔗

ModuleWhat it gives you
std.mathPI, E, TAU, clamp, sign, factorial, gcd, lcm, mean
std.itermap, filter, reduce, take, drop, zip, enumerate, all, any, count, find, find_index, flatten, sum, product, min_array, max_array
std.collectionsStack, Queue, Set as value-semantics structs
std.stringpad_left, pad_right, center, chars, reverse, is_palindrome, count, join
std.jsonparse, stringify (RFC-8259, pure Bop)
std.testassert, assert_eq, assert_near, assert_raises

Using the stdlib🔗

std modules work with every use form:

use std.math                   // glob — `PI`, `clamp`, etc. available bare
use std.iter.{map, filter}     // selective
use std.json as j              // aliased

The modules are plain Bop source — you can find the implementations in bop/src/modules/*.bop if you want to see how a helper is wired, or copy-paste the source into a host that doesn’t ship bop-std.

Things you might expect to find here🔗

  • Result combinatorsis_ok, is_err, unwrap, expect, unwrap_or, map, map_err, and_then used to live in std.result. They’re now methods on the built-in Result type and always available without any import. See Methods → Result.
  • print, range, rand, try_call, panic — always-in-scope built-in functions, not stdlib.
  • Math on numbersabs, sqrt, sin, cos, floor, ceil, round, pow, log, exp, min, max, to_int, to_float are methods on int / number, not stdlib.

Hosts without the stdlib🔗

Embedders who don’t want bop-std on the host side can leave resolve_module unimplemented; any use std.* then fails with “can’t resolve module”. Nothing about the language depends on the stdlib — it’s a convenience, not a runtime prerequisite.

Found something unclear?Edit this page on GitHub
Documentation

Search Bop

Start typing to search the guide and reference.