Builtin Functions
Functions
abs · builtin_names · cbrt · ceil · chars · child_types · clamp · contains · cos · decl_info · decorator_names · doc_comment · ends_with · exp · filter · find · flatten · floor · fn_signature · fold · format · head · hypot · join · keys · len · ln · log10 · log2 · map · map_values · max · merge · min · pow · replace · round · sign · sin · slice · split · sqrt · starts_with · tail · tan · to_lower · to_upper · trim · trunc · type_fields · values
abs(x: f64) → f64
Absolute value.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
abs(-7.5) // magnitude, dropping the sign → 7.5builtin_names() → [utf8]
The names of every registered built-in function, sorted. Pair with fn_signature to introspect each one.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| returns | [utf8] | Every built-in's name, sorted alphabetically. | — |
builtin_names() // names of every builtin → ["abs", "acos", ..., "zip"]cbrt(x: f64) → f64
Cube root.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
cbrt(27) // cube root → 3.0ceil(x: f64) → f64
Round up to the nearest integer.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
ceil(3.1) // round up to a whole number → 4.0chars(s: utf8) → [utf8]
The characters of a string as a list of one-character strings.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| s | utf8 | The string to split into characters. | — |
| returns | [utf8] | One string per character. | — |
chars("abc") // explode into single-character strings → ["a", "b", "c"]child_types(target: &T) → [&T]
Reflect a type into references to the element types of its @child / @children block slots (own slots first, then inherited via extends). Pair with type_table / type_fields to auto-document the blocks a @document declares.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| target | &T | A reference to a type or interface declaration. | — |
| returns | [&T] | One type reference per block slot. Slots that accept a union or interface resolve to that type's name; scalar (non-block) fields are skipped. | — |
child_types(MyDoc) // element types of the doc’s block slots → [&ProjectMeta, &Settings]clamp(x: number, lo: number, hi: number) → f64
Constrain x to the range [lo, hi].
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | number | The value to clamp. | — |
| lo | number | The lower bound. | — |
| hi | number | The upper bound. | — |
| returns | f64 | x limited to [lo, hi], as an f64. | — |
clamp(12.0, 0.0, 10.0) // constrain the value into [0, 10] → 10.0contains(s: utf8, needle: utf8) → bool
Whether a string contains a substring.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| s | utf8 | The string to search. | — |
| needle | utf8 | The substring to look for. | — |
| returns | bool | true if the substring is present. | — |
contains("hello", "ell") // does the string contain the substring? → truecos(x: f64) → f64
Cosine of an angle in radians.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
cos(0.0) // cosine of 0 radians → 1.0decl_info(target: &T) → record
Describe a top-level declaration: its name, kind, doc comment, and schema classification (block / table / decorator / document).
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| target | &T | A reference to a type, interface, union, or symbol_set declaration. | — |
| returns | record | { name, full_name, kind, doc, is_imported, is_document, block_kind, table_kind, decorator_name, extends }. The classification fields are none when the decorator is absent. | — |
decl_info(MyDoc) // declaration metadata for a type → { kind: "document", is_document: true, name: "MyDoc" }decorator_names(target: &T) → [utf8]
List the names of the decorators attached to a referenced declaration.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| target | &T | A reference to a type, field, block, or variant. | — |
| returns | [utf8] | The decorator names, in source order. | — |
decorator_names(Image) // the decorators on the Image type → ["block", "schemaless", ...]doc_comment(target: &T) → utf8
The doc comment — the contiguous run of # / // lines immediately above a declaration — attached to a reference, or \"\" when there is none. Complements decorator_arg(x, \"doc\", …) for @doc(\"…\") metadata.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| target | &T | A reference to a type, interface, union, variant, symbol_set, or field. | — |
| returns | utf8 | The joined comment text, or \"\" when absent. | — |
doc_comment(Image) // the doc comment above a type → the comment lines above the Image typeends_with(s: utf8, suffix: utf8) → bool
Whether a string ends with a suffix.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| s | utf8 | The string to test. | — |
| suffix | utf8 | The suffix to look for. | — |
| returns | bool | true if the string ends with the suffix. | — |
ends_with("hello", "lo") // does it end with this suffix? → trueexp(x: f64) → f64
e raised to the power x.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
exp(0.0) // e raised to the power 0 → 1.0filter(xs: [T], pred: fn (T) -> bool) → [T]
Keep only the list elements for which the predicate returns true.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| xs | [T] | The list to filter. | — |
| pred | fn (T) -> bool | Predicate deciding whether to keep an element. | — |
| returns | [T] | The elements for which the predicate returned true. | — |
filter([1, 2, 3, 4], fn(x: i64) -> bool { x % 2 == 0 }) // keep the even numbers → [2, 4]find(xs: [T], pred: fn (T) -> bool) → T
The first element for which the predicate returns true, or none.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| xs | [T] | The list to search. | — |
| pred | fn (T) -> bool | Predicate applied to each element. | — |
| returns | T | The first matching element, or none. | — |
find([1, 2, 3], fn(x: i64) -> bool { x > 1 }) // first element greater than 1 → 2flatten(xss: [[T]]) → [T]
Concatenate a list of lists into a single list, one level deep.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| xss | [[T]] | A list whose elements are themselves lists. | — |
| returns | [T] | The inner lists concatenated, one level deep. | — |
flatten([[1, 2], [3]]) // concatenate the inner lists, one level deep → [1, 2, 3]floor(x: f64) → f64
Round down to the nearest integer.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
floor(3.9) // round down to a whole number → 3.0fn_signature(f: any) → record
Describe a function's parameters and return type. Pass a function value, or a built-in's name as a string.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| f | any | A function value, or the name of a built-in as a utf8 string. | — |
| returns | record | A record { doc, params: [{name, type, doc}], return_type, return_doc, signature, is_builtin }. | — |
fn_signature("map") // describe the map builtin → { signature: "fn(xs: [T], ...) -> [U]", ... }fold(xs: [T], init: U, f: fn (U, T) -> U) → U
Reduce a list or tensor to a single value by repeatedly combining the accumulator with each element.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| xs | [T] | The list or tensor to reduce. | — |
| init | U | The initial accumulator value. | — |
| f | fn (U, T) -> U | Combines the accumulator with the next element. | — |
| returns | U | The final accumulator value. | — |
fold([1, 2, 3], 0, fn(acc: i64, x: i64) -> i64 { acc + x }) // sum the list, starting from 0 → 6format(template: utf8) → utf8
Substitute trailing arguments into a template's {} placeholders ({{/}} are literal braces).
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| template | utf8 | Template string with {} placeholders. | — |
| returns | utf8 | The template with placeholders substituted. | — |
format("{} = {}", "x", 42) // substitute the args into the {} slots → "x = 42"head(xs: [T]) → T
The first element of a list or tensor (none when empty).
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| xs | [T] | A list or tensor. | — |
| returns | T | The first element, or none if empty. | — |
Remarks: Returns none when the collection is empty.
head([1, 2, 3]) // take the first element → 1hypot(a: f64, b: f64) → f64
Length of the hypotenuse sqrt(a² + b²).
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| a | f64 | The first operand. | — |
| b | f64 | The second operand. | — |
| returns | f64 | The result. | — |
hypot(3, 4) // hypotenuse of a 3-4 right triangle → 5.0join(parts: [utf8], sep: utf8) → utf8
Join a list of strings into one, inserting a separator between each.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| parts | [utf8] | The strings to join. | — |
| sep | utf8 | The separator inserted between parts. | — |
| returns | utf8 | The joined string. | — |
join(["a", "b", "c"], "-") // join with a dash between pieces → "a-b-c"keys(r: record) → [utf8]
The field names of a record, in deterministic (sorted) order.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| r | record | A record value (or a union variant with a record body). | — |
| returns | [utf8] | The field names. | — |
keys({ name: "Rex", age: 4 }) // field names, sorted → ["age", "name"]len(xs: [T]) → usize
The number of elements in a list or tensor, or characters in a string.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| xs | [T] | A list, tensor, or string. | — |
| returns | usize | The number of elements (or characters). | — |
len([10, 20, 30]) // count the elements → 3ln(x: f64) → f64
Natural (base-e) logarithm.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
ln(1.0) // natural (base-e) logarithm of 1 → 0.0log10(x: f64) → f64
Base-10 logarithm.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
log10(1000.0) // base-10 logarithm of 1000 → 3.0log2(x: f64) → f64
Base-2 logarithm.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
log2(8.0) // base-2 logarithm of 8 → 3.0map(xs: [T], f: fn (T) -> U) → [U]
Apply a function to every element of a list or tensor, returning the transformed collection.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| xs | [T] | The list or tensor to transform. | — |
| f | fn (T) -> U | Function applied to each element. | — |
| returns | [U] | A new collection of the transformed elements. | — |
map([1, 2, 3], fn(x: i64) -> i64 { x * 2 }) // double each element → [2, 4, 6]map_values(r: record, f: fn (T) -> U) → record
Apply a function to every field value of a record, keeping the keys.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| r | record | The record to transform. | — |
| f | fn (T) -> U | Function applied to each field value. | — |
| returns | record | A record with the same keys and transformed values. | — |
map_values({ low: 1, high: 9 }, fn(x: i64) -> i64 { x * 2 }) // double every value, keep the keys → { high: 18, low: 2 }max(a: f64, b: f64) → f64
The larger of two numbers.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| a | f64 | The first operand. | — |
| b | f64 | The second operand. | — |
| returns | f64 | The result. | — |
max(3, 7.5) // the larger of the two → 7.5merge(a: record, b: record) → record
Combine two records into one; fields of b win on a name clash.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| a | record | The base record. | — |
| b | record | The overriding record. | — |
| returns | record | A record with the union of both field sets. | — |
merge({ host: "localhost", port: 80 }, { port: 8080 }) // the second record wins on the port clash → { host: "localhost", port: 8080 }min(a: f64, b: f64) → f64
The smaller of two numbers.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| a | f64 | The first operand. | — |
| b | f64 | The second operand. | — |
| returns | f64 | The result. | — |
min(3, 7.5) // the smaller of the two → 3.0pow(a: f64, b: f64) → f64
Raise a to the power b.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| a | f64 | The first operand. | — |
| b | f64 | The second operand. | — |
| returns | f64 | The result. | — |
pow(2, 10) // 2 raised to the 10th power → 1024.0replace(s: utf8, old: utf8, new: utf8) → utf8
Replace every occurrence of a substring with another.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| s | utf8 | The string to search. | — |
| old | utf8 | The substring to find. | — |
| new | utf8 | The replacement substring. | — |
| returns | utf8 | The string with every match replaced. | — |
replace("hello world", "world", "there") // replace the matched substring → "hello there"round(x: f64) → f64
Round to the nearest integer (ties away from zero).
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
round(2.5) // nearest integer (ties away from zero) → 3.0sign(x: f64) → f64
The sign of x: 1, -1, or 0.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
sign(-3.0) // negative input -> -1.0 → -1.0sin(x: f64) → f64
Sine of an angle in radians.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
sin(0.0) // sine of 0 radians → 0.0slice(xs: utf8 | [T], start: i64, end: i64) → utf8 | [T]
The half-open range [start, end) of a string's characters or a list's elements (bounds are clamped).
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| xs | utf8 | [T] | The string or list to slice. | — |
| start | i64 | Inclusive start index (clamped to the length). | — |
| end | i64 | Exclusive end index (clamped to the length). | — |
| returns | utf8 | [T] | The sub-string / sub-list. | — |
slice("hello", 0, 2) // characters from index 0 up to (not incl.) 2 → "he"split(s: utf8, sep: utf8) → [utf8]
Split a string on every occurrence of a separator into a list of pieces.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| s | utf8 | The string to split. | — |
| sep | utf8 | The separator to split on. | — |
| returns | [utf8] | The pieces between separators. | — |
split("a,b,c", ",") // split on each comma → ["a", "b", "c"]sqrt(x: f64) → f64
Square root.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
sqrt(144) // square root → 12.0starts_with(s: utf8, prefix: utf8) → bool
Whether a string begins with a prefix.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| s | utf8 | The string to test. | — |
| prefix | utf8 | The prefix to look for. | — |
| returns | bool | true if the string starts with the prefix. | — |
starts_with("hello", "he") // does it begin with this prefix? → truetail(xs: [T]) → [T]
Every element of a list or tensor except the first.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| xs | [T] | A list or tensor. | — |
| returns | [T] | The elements after the first. | — |
tail([1, 2, 3]) // everything after the first → [2, 3]tan(x: f64) → f64
Tangent of an angle in radians.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
tan(0.0) // tangent of 0 radians → 0.0to_lower(s: utf8) → utf8
Lowercase every character of a string.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| s | utf8 | The string to lowercase. | — |
| returns | utf8 | The lowercased string. | — |
to_lower("AbC") // lowercase every character → "abc"to_upper(s: utf8) → utf8
Uppercase every character of a string.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| s | utf8 | The string to uppercase. | — |
| returns | utf8 | The uppercased string. | — |
to_upper("abc") // uppercase every character → "ABC"trim(s: utf8) → utf8
Remove leading and trailing whitespace from a string.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| s | utf8 | The string to trim. | — |
| returns | utf8 | The string without leading/trailing whitespace. | — |
trim(" hi ") // strip leading/trailing whitespace → "hi"trunc(x: f64) → f64
Discard the fractional part, rounding toward zero.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| x | f64 | The input value. | — |
| returns | f64 | The result. | — |
trunc(3.9) // drop the fractional part → 3.0type_fields(target: &T) → [record]
Reflect a type or interface into a list of field-description records (own fields first, then inherited via extends).
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| target | &T | A reference to a type or interface declaration. | — |
| returns | [record] | One record per field: { name, type, is_function, optional, has_default, is_block, repeated, accepts, decorators }. | — |
type_fields(Image) // reflect the Image type into field records → [{ name: "source", type: "utf8", ... }, ...]values(r: record) → [T]
The field values of a record, in the same order as keys.
| Parameter | Type | Description | Remarks |
|---|---|---|---|
| r | record | A record value (or a union variant with a record body). | — |
| returns | [T] | The field values. | — |
values({ name: "Rex", age: 4 }) // field values, in key order → [4, "Rex"]