PCD Standard Library
The BRIK-64 standard library is written 100% in PCD. There is no Rust, no C, no FFI. Every stdlib function compiles through the same pipeline as user code, producing the same verified ELF, BIR, or WASM output. This is the proof of concept: a language whose standard library is written in itself, formally verified by the TCE, and compiled to native code by the self-hosting compiler.All stdlib modules are located in the
stdlib/ directory relative to your project root. Import them with import "stdlib/module.pcd";.Module Overview
| Module | File | Functions |
|---|---|---|
| math | stdlib/math.pcd | abs, min, max, clamp, pow, sqrt, floor, ceil, round, sign, gcd, lcm |
| string | stdlib/string.pcd | len, upper, lower, trim, split, join, find, contains, starts_with, ends_with, replace, format, to_int, from_int, char_at, substr |
| array | stdlib/array.pcd | len, push, pop, get, set, sort, reverse, map, filter, reduce, contains, find_index, slice, concat, zip, flatten |
| io | stdlib/io.pcd | read_file, write_file, read_line, write_line, exists, read_bytes, write_bytes |
| fmt | stdlib/fmt.pcd | format, to_string, pad_left, pad_right, truncate, repeat, center |
| json | stdlib/json.pcd | parse, stringify, get, set, keys, values, has, merge |
math
abs(n: i64) → i64
Returns the absolute value of n.
min(a: i64, b: i64) → i64
Returns the smaller of two values.
max(a: i64, b: i64) → i64
Returns the larger of two values.
clamp(val: i64, lo: i64, hi: i64) → i64
Clamps val to the range [lo, hi].
pow(base: i64, exp: i64) → i64
Returns base raised to the power exp. Uses fast exponentiation (O(log exp)).
sqrt(n: i64) → i64
Integer square root (floor). Returns the largest integer k such that k*k ≤ n.
floor(n: i64) → i64
Identity for integers. Provided for type-consistent APIs.
ceil(n: i64) → i64
Identity for integers. Provided for type-consistent APIs.
sign(n: i64) → i64
Returns -1, 0, or 1 depending on the sign of n.
gcd(a: i64, b: i64) → i64
Greatest common divisor via Euclidean algorithm.
lcm(a: i64, b: i64) → i64
Least common multiple.
string
len(s: string) → i64
Returns the number of characters in s.
upper(s: string) → string
Converts all lowercase letters to uppercase.
lower(s: string) → string
Converts all uppercase letters to lowercase.
trim(s: string) → string
Removes leading and trailing whitespace.
split(s: string, delim: string) → array
Splits s on delim, returns an array of substrings.
join(arr: array, sep: string) → string
Joins an array of strings with sep.
find(s: string, sub: string) → i64
Returns the index of the first occurrence of sub in s, or -1 if not found.
contains(s: string, sub: string) → bool
Returns true if s contains sub.
starts_with(s: string, prefix: string) → bool
ends_with(s: string, suffix: string) → bool
replace(s: string, from: string, to: string) → string
Replaces all occurrences of from with to.
format(template: string, args: array) → string
Replaces {} placeholders with array elements in order.
to_int(s: string) → i64
Parses a decimal integer string. Returns 0 for invalid input.
from_int(n: i64) → string
Converts an integer to its decimal string representation.
char_at(s: string, i: i64) → string
Returns the character at index i as a single-character string.
substr(s: string, start: i64, length: i64) → string
Returns a substring of s starting at start with the given length.
array
len(arr: array) → i64
push(arr: array, elem) → array
Returns a new array with elem appended.
pop(arr: array) → (array, value)
Returns a tuple of (new_array, last_element).
get(arr: array, i: i64) → value
Returns element at index i. Equivalent to arr[i].
set(arr: array, i: i64, val) → array
Returns a new array with element at index i replaced by val.
sort(arr: array) → array
Returns a new array sorted in ascending order (integers or strings).
reverse(arr: array) → array
Returns a new array with elements in reverse order.
map(arr: array, f: closure) → array
Applies f to each element, returns new array of results.
filter(arr: array, pred: closure) → array
Returns new array of elements for which pred returns true.
reduce(arr: array, initial, f: closure) → value
Folds arr from left with accumulator starting at initial.
contains(arr: array, elem) → bool
Returns true if elem is in arr.
find_index(arr: array, elem) → i64
Returns the index of the first occurrence of elem, or -1.
slice(arr: array, start: i64, end: i64) → array
Returns elements from start (inclusive) to end (exclusive).
concat(a: array, b: array) → array
Concatenates two arrays.
zip(a: array, b: array) → array
Pairs elements: returns array of tuples.
flatten(arr: array) → array
Flattens one level of nesting.
io
read_file(path: string) → string
Reads the entire file at path as a UTF-8 string.
write_file(path: string, content: string)
Writes content to path, creating or overwriting the file.
read_line() → string
Reads a single line from stdin (without trailing newline).
write_line(s: string)
Writes s followed by a newline to stdout.
exists(path: string) → bool
Returns true if the file at path exists.
read_bytes(path: string) → array
Reads file as array of byte values (i64 in 0–255 range).
write_bytes(path: string, bytes: array)
Writes array of byte values to file.
fmt
format(template: string, args: array) → string
String interpolation with {} placeholders. Each {} is replaced by the next element of args, converted to string:
to_string(val) → string
Converts any value to its string representation.
pad_left(s: string, width: i64, ch: string) → string
Pads s on the left to reach width characters, using ch as padding character.
pad_right(s: string, width: i64, ch: string) → string
Pads s on the right.
truncate(s: string, max_len: i64) → string
Truncates s to max_len characters.
repeat(s: string, n: i64) → string
Repeats s exactly n times.
center(s: string, width: i64, ch: string) → string
Centers s within width characters, padding with ch.
json
(key, value) tuple pairs, JSON arrays are PCD arrays, and JSON primitives map to their PCD equivalents.
parse(s: string) → value
Parses a JSON string into a PCD value.
stringify(val) → string
Serializes a PCD value to a JSON string.
get(obj, key: string) → value
Gets a field from a JSON object by key.
set(obj, key: string, val) → value
Returns a new object with the field set.
keys(obj) → array
Returns an array of the object’s keys.
values(obj) → array
Returns an array of the object’s values.
has(obj, key: string) → bool
Returns true if obj has the given key.
merge(a, b) → value
Merges two JSON objects. Fields in b override fields in a.