Standard Library
Every shipped stdlib module: strings, collections, memory, math, time, I/O, networking, HTTP, JSON, and more.
Every module is an ordinary .tr file under lib/std/ — no compiler special-casing, and import <module>; doesn’t care which subfolder it lives in. int/double/bool/char/strings/array are auto-imported into every file (the “prelude”); everything else needs an explicit import.
Module reference
| Module | What it gives you |
|---|---|
strings | length/contains/index_of/starts_with/ends_with/repeat/substring/replace/to_upper/to_lower/trim(_start/_end), split/join, pad_left/pad_right, parse_int/parse_double |
io | print/printline/input, plus file I/O: read_to_string, read_lines, write_string, exists, eprint/eprintline, flush |
list / stack / queue / map / collections::set | List<T>/Stack<T>/Queue<T>/Map<K,V>/Set<T>, plus list_sort/list_binary_search/list_find free functions over List<int> |
mem | checked alloc/alloc_zeroed/grow/dup/zero wrappers over malloc/calloc/realloc/free, plus Pool<T> |
math | abs/power/min/max/clamp, libm bindings (sqrt, sin, pow, …), PI/E |
time | now_seconds() (wall clock), clock_ticks()/elapsed_ms() (CPU time — not wall time), sleep_seconds/sleep_ms |
random | random_int/random_double/random_bool — not cryptographically secure |
fs | path manipulation (join/dirname/basename/extension/is_absolute) and directory ops (mkdir/remove_file/remove_dir/is_dir) |
net | TcpListener/TcpConnection, plus resolve_hostname for DNS |
http | Request/Response HTTP/1.1 parsing/building over net, plus a callback-based Server router |
json | a hand-rolled, dependency-free JsonValue parser/serializer (json::parse/json::stringify) |
os | env/set_env, argc/argv |
sys / test | panic/exit/abort; assert/fail/assert_eq |
Full per-function reference for every module lives in the repo at docs/reference/stdlib/, one page per module.
Collections
List<T>, Stack<T>, Queue<T>, Map<K, V>, and Set<T> are ordinary generic structs written in Turf itself, not compiler-magic containers:
import list::List;
mut nums: List<int> = List::default();
nums.push(10);
nums.push(20);
assert(nums.length() == 2, "");
map and collections::set also provide free functions over List<int> specifically: list_sort, list_binary_search, list_find.
Known limitation
Map<K, V>/Set<T> lookups compare keys/items by raw identity, not content, when K/T = string (correct for int/double/bool/pointer). The root cause is type erasure: a generic method body is checked and codegenned once, shared across every instantiation, so it can never see the concrete string type to dispatch strings.tr’s real operator== through. Set<string> dedup and Map<string, V>’s own .get()/.contains()/.tryGet() are affected.
The real fix is either per-instantiation codegen (true monomorphization) or a trait/constraint system — both substantial compiler changes, tracked post-1.0.0 in the roadmap. In the meantime, lib/std/http.tr’s Request/Server code demonstrates the working non-generic-method pattern that sidesteps the gap: do the string comparison in an ordinary (non-generic) function instead of inside the generic method body, where the concrete string type is still visible to the type checker.
Nothing else in the standard library has a known live bug as of v1.0.0.
FFI-backed modules
Several modules are thin, checked wrappers over C library calls rather than pure-Turf logic:
memwrapsmalloc/calloc/realloc/freewith bounds/null checks and addsPool<T>, a simple arena allocator.mathbindslibmdirectly (sqrt,sin,pow, …) viaextern from "m" fn.netimplementsTcpListener/TcpConnectionover BSD sockets, plus DNS resolution.fswraps directory/path syscalls.
http and json are pure Turf built on top of net and the core language — no external C dependencies, matching the “ships with a real standard library” pitch in the project overview.
Examples using the stdlib together
The showcase/ directory in the repo has larger, real-world-shaped programs exercising these modules in combination — an HTTP server and a companion Turf HTTP client talking over a real TCP socket (both ends written in Turf, using nothing but standard-library modules), a key-value store client/server pair, an LLVM-C FFI demo, a text-analysis tool exercising strings/fs/Set/sort-and-search/time, and a JSON-config-driven dice roller exercising json/random/net::resolve_hostname.