Standard Library
Standard helpers live under the std:: namespace. Like msg:: and sys::,
std:: is always in scope — no import is required.
Ready-to-deploy token and vault entities, plus extra integer helpers, live
in the separate Contract Standard Library
(stdlib/ in cambrian-lang). Those are ordinary .cam files you import
or list in project.yaml; they are not std:: names.
Bare legacy names such as min(a, b) or sha256(data) are rejected
(V49) unless you declared a pure fn of that name. Always write the
qualified form.
std::math
All functions are pure. Operand types must match unless the signature documents widening (same rules as binary arithmetic).
| Function | Role |
|---|---|
std::math::min(a, b) | Smaller of two values |
std::math::max(a, b) | Larger of two values |
std::math::abs(x) | Absolute value (signed) |
std::math::clamp(x, lo, hi) | Clamp to [lo, hi] |
std::math::muldiv(x, y, z) | (x * y) / z with a wide intermediate |
std::math::muldivmod(x, y, z) | Quotient and remainder, wide intermediate |
std::math::divmod(x, y) | (quotient, remainder) |
std::math::divc(x, y) | Division rounding up |
std::math::divr(x, y) | Division rounding to nearest |
std::math::sign(x) | -1, 0, or 1 (signed) |
std::math::minmax(a, b) | (min, max) pair |
std::math::modpow2(x, n) | x % 2^n (mask semantics) |
std::math::pow(x, n) | Exponentiation (n: u64) |
Numeric types: supported integer widths (u8…u128, i8…i128, U256)
where the operation is defined. Unsupported combinations fail at transpile
time.
A user pure fn may have the same name as a std function (min, max,
pow, …): a bare min(a, b) then calls your function, and
std::math::min(a, b) always calls the builtin.
std::math::muldivmod is EVM-only (no Lean lowering).
On EVM, call the pair-returning functions (divmod, minmax, muldivmod)
and the signed helpers (abs, sign) from a pure fn body. In a route
body, let (q, r) = std::math::divmod(x, y); is rejected, and a let bound
to abs / sign does not yet compile:
pure fn split(x: U256, y: U256) -> (U256, U256) {
let (q, r) = std::math::divmod(x, y);
(q, r)
}
std::str
Parsing
std::str::parse_u64(s: String, radix: u64) -> Option<u64>
std::str::parse_u8 / parse_u16 / parse_u32 / parse_u128 / parse_U256
std::str::parse_i8 / parse_i16 / parse_i32 / parse_i64 / parse_i128
std::str::parse_uint(s, radix) -> Option<u64> // alias of parse_u64
std::str::parse_int(s, radix) -> Option<i64> // alias of parse_i64
Each parse_<T> returns Option<T>.
Parse all characters of s with radix in 2..=36. Leading 0x / 0X
forces base 16 (radix must be 16 or 0). Overflow, empty string, bad digit,
or bad radix yields none.
let n = match std::str::parse_u64(s, 10) {
some(v) => v,
none => 0
};
Formatting
std::str::format(fmt: String, ...) -> String
Phase-1 format specs:
| Spec | Meaning |
|---|---|
{} | Default display |
{:w} | Minimum width w |
{:0w} | Zero-pad to width w (for example {:06} → 000042) |
Arguments may be integers or strings.
std::crypto
| Function | Signature | Semantics |
|---|---|---|
std::crypto::sha256 | (bytes or String) -> bytes | SHA-256 digest (32 bytes) |
view digest(data: bytes) -> bytes => [
return(std::crypto::sha256(data))
]
std::crypto::sha256 currently lowers only on EVM; it has no Lean lowering
(L13). On EVM, evm::sha256 is also available for explicit platform
intent — see EVM Intrinsics.
Strict typing (V50)
There is no implicit string↔number coercion in member transforms, returns, or sends:
String→ numeric member withoutstd::str::parse_*→ V50- numeric expression assigned / returned as
Stringwithoutstd::str::format→ V50
Collection helpers (len, map, fold, …) stay method syntax on Vec,
HashMap, and Option — they are not bare global functions.
See also
- Contract Standard Library —
stdlib/math.cam, ERC-20 / ERC-7943 tokens, ERC-4626 vaults - EVM Intrinsics