Guide
Standard library
The stdlib is written in POLYTONE itself — plain .pt modules, self-tested with test blocks, imported like any module.
import lists
import texts
fn main() -> Void:
let squares = lists.range(1, 6).map(fn(x: Int) -> Int = x * x)
print("sum: {lists.sum(squares)}")
print("padded: {texts.pad_left("7", 4, "0")}")import resolves next to your file first, then in the stdlib ($POLYTONE_STDLIB or the checkout's stdlib/) — a local file always shadows the stdlib. The batteries have grown well past the v0.1 trio: alongside ints, lists, texts, and maths there are the generic collections (sets, maps), data formats (json, csv, toml), encoding (base64, hex, url), crypto (sha256, hmac_sha256, crc32), uuid v4 (on the Rng capability), time, patterns — a real regex subset with alternation, groups, {n,m} quantifiers, and capture extraction — and the http helpers for the Http capability. The full, exact API — every signature and doc — is on the API reference page, generated from the shipping stdlib.
import crypto
import base64
fn main() -> Void:
let msg = "polytone".to_bytes()
print("sha256: {crypto.sha256_hex(msg)}")
print("base64: {base64.encode(msg)}")crypto and base64 are pure POLYTONE, written on the bitwise operators (& | ^ << >> ~, Sprint 90) — the same primitives you'd reach for, in the same language. Nothing here is a native builtin.
import patterns
fn main() -> Void:
match patterns.captures("(\\w+)@(\\w+)\\.(\\w+)", "ada@polytone.dev"):
case Ok(Some(parts)):
print("user={parts[1]} host={parts[2]}.{parts[3]}")
case Ok(None):
print("no match")
case Err(e):
print("bad pattern: {e}")patterns.matches(pattern, text) validates against the whole text and patterns.captures pulls out each group's substring — a real regex engine (alternation, groups, {n,m}) written in POLYTONE, matched by a deduped position-set simulation that is polynomial and ReDoS-safe. It is a documented subset: no backreferences, lookaround, or lazy quantifiers.