All builtin functions
Every WCL builtin in alphabetical order. Each signature links to its full reference page.
| Function | Description |
|---|---|
| abs(x: f64) → f64 | Absolute value. |
| acos(x: number) → f64 | Arccosine, in radians, of a value in [-1, 1]. |
| [all(xs: [T], pred: fn (T) -> bool) → bool](functionfnall) | true when the predicate holds for every element (short-circuits; true for an empty list). |
| [any(xs: [T], pred: fn (T) -> bool) → bool](functionfnany) | true when the predicate holds for at least one element (short-circuits). |
| asin(x: number) → f64 | Arcsine, in radians, of a value in [-1, 1]. |
| assert(cond: bool, msg: utf8) → none | Return none when cond is true, otherwise abort with msg. |
| ast_string(target: &T) → utf8 | Pretty-print the canonical source behind a reference (type/interface/union/symbol_set/block/field) or a function value. |
| [at(xs: [T], i: i64) → T](functionfnat) | The element at a zero-based index; errors if out of bounds or negative. |
| atan(x: number) → f64 | Arctangent, in radians. |
| atan2(a: number, b: number) → f64 | Arctangent of a/b in radians, using the signs of both to pick the quadrant. |
| [builtin_names() → [utf8]](functionfnbuiltin_names) | The names of every registered built-in function, sorted. Pair with fn_signature to introspect each one. |
| cbrt(x: f64) → f64 | Cube root. |
| ceil(x: f64) → f64 | Round up to the nearest integer. |
| [chars(s: utf8) → [utf8]](functionfnchars) | The characters of a string as a list of one-character strings. |
| [child_types(target: &T) → [&T]](functionfnchild_types) | 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. |
| clamp(x: number, lo: number, hi: number) → f64 | Constrain x to the range [lo, hi]. |
| concat(a: utf8, b: utf8) → utf8 | Concatenate two strings into one. |
| contains(s: utf8, needle: utf8) → bool | Whether a string contains a substring. |
| cos(x: f64) → f64 | Cosine of an angle in radians. |
| decl_info(target: &T) → record | Describe a top-level declaration: its name, kind, doc comment, and schema classification (block / table / decorator / document). |
| decorator_arg(target: &T, decorator: utf8, slot: utf8) → any | Read one named argument of a decorator on a referenced declaration (none if absent). |
| [decorator_names(target: &T) → [utf8]](functionfndecorator_names) | List the names of the decorators attached to a referenced declaration. |
| degrees(x: number) → f64 | Convert an angle from radians to degrees. |
| 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. |
| [drop(xs: [T], n: i64) → [T]](functionfndrop) | Every element of a list after the first n. |
| e() → f64 | Euler's number e (≈ 2.71828). |
| ends_with(s: utf8, suffix: utf8) → bool | Whether a string ends with a suffix. |
| [enumerate(xs: [T]) → [[i64, T]]](functionfnenumerate) | Pair every element with its zero-based index, as [index, element] pairs. |
| error(msg: utf8) → never | Abort evaluation with an error message. |
| eval(src: utf8) → any | Parse a string as a WCL expression and evaluate it in the current scope. |
| exp(x: f64) → f64 | e raised to the power x. |
| [filter(xs: [T], pred: fn (T) -> bool) → [T]](functionfnfilter) | Keep only the list elements for which the predicate returns true. |
| [find(xs: [T], pred: fn (T) -> bool) → T](functionfnfind) | The first element for which the predicate returns true, or none. |
| [flatten(xss: [[T]]) → [T]](functionfnflatten) | Concatenate a list of lists into a single list, one level deep. |
| floor(x: f64) → f64 | Round down to the nearest integer. |
| fn_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. |
| [fold(xs: [T], init: U, f: fn (U, T) -> U) → U](functionfnfold) | Reduce a list or tensor to a single value by repeatedly combining the accumulator with each element. |
| format(template: utf8) → utf8 | Substitute trailing arguments into a template's {} placeholders ({{/}} are literal braces). |
| format_unit(value: i64, type: utf8, unit: utf8) → utf8 | Render a base-unit value in a chosen literal unit, looking the factor up from a unit type by name — the inverse of literal-unit resolution, so it stays correct if the type's @unit factor changes. |
| format_unit_value(value: i64, factor: i64, unit: utf8) → utf8 | Render a number in a unit given its factor explicitly — the primitive behind format_unit for callers that already hold the factor. |
| glob_match(pattern: utf8, path: utf8) → bool | Match one concrete path against a glob. * stays within a segment, ** spans segments, ? matches one character, [a-z] / [!x] are character classes. A trailing / on the pattern matches the whole subtree. |
| glob_overlaps(a: utf8, b: utf8) → bool | Whether two glob patterns can match a common path. Concrete paths are patterns too, so this subsumes glob_match for overlap gates. Trailing / means the whole subtree. Conservative: exotic negated-class pairings may report true when no shared path exists, never false when one does. |
| [group_by(xs: [T], key: fn (T) -> K) → [record]](functionfngroup_by) | Group elements by a key function into { key, items } records, in first-seen key order. |
| [head(xs: [T]) → T](functionfnhead) | The first element of a list or tensor (none when empty). |
| hypot(a: f64, b: f64) → f64 | Length of the hypotenuse sqrt(a² + b²). |
| [index_of(xs: [T], needle: T) → i64](functionfnindex_of) | The index of the first element equal to needle, or -1 if absent. |
| [join(parts: [utf8], sep: utf8) → utf8](functionfnjoin) | Join a list of strings into one, inserting a separator between each. |
| [keys(r: record) → [utf8]](functionfnkeys) | The field names of a record, in deterministic (sorted) order. |
| [len(xs: [T]) → usize](functionfnlen) | The number of elements in a list or tensor, or characters in a string. |
| [list_contains(xs: [T], needle: T) → bool](functionfnlist_contains) | Whether a list contains a value equal to needle. |
| ln(x: f64) → f64 | Natural (base-e) logarithm. |
| log10(x: f64) → f64 | Base-10 logarithm. |
| log2(x: f64) → f64 | Base-2 logarithm. |
| [map(xs: [T], f: fn (T) -> U) → [U]](functionfnmap) | Apply a function to every element of a list or tensor, returning the transformed collection. |
| map_values(r: record, f: fn (T) -> U) → record | Apply a function to every field value of a record, keeping the keys. |
| max(a: f64, b: f64) → f64 | The larger of two numbers. |
| [max_by(xs: [T], key: fn (T) -> K) → T](functionfnmax_by) | The element with the largest key, or none for an empty list. |
| merge(a: record, b: record) → record | Combine two records into one; fields of b win on a name clash. |
| min(a: f64, b: f64) → f64 | The smaller of two numbers. |
| [min_by(xs: [T], key: fn (T) -> K) → T](functionfnmin_by) | The element with the smallest key, or none for an empty list. |
| [namespace_decls(ns: utf8) → [&T]](functionfnnamespace_decls) | List references to every top-level declaration (type / interface / union / symbol_set) in a namespace, for schema-documentation generators. Pair with decl_info, doc_comment, type_fields, and ast_string to render each. Imported (library) declarations are included — filter on decl_info(d).is_imported to drop them. |
| pad_end(s: utf8, width: i64, pad: utf8) → utf8 | Right-pad a string with a fill pattern until it is width characters long. |
| pad_start(s: utf8, width: i64, pad: utf8) → utf8 | Left-pad a string with a fill pattern until it is width characters long. |
| panic(msg: utf8) → never | Abort evaluation with an unrecoverable failure message. |
| path_contains(parent: utf8, child: utf8) → bool | Segment-aware path prefix test: whether child is parent itself or lives under it. Splits on /, so src/ does not contain src2/x. A path contains itself. |
| pi() → f64 | The constant π (≈ 3.14159). |
| pow(a: f64, b: f64) → f64 | Raise a to the power b. |
| radians(x: number) → f64 | Convert an angle from degrees to radians. |
| [range(start: i64, end: i64) → [i64]](functionfnrange) | The half-open integer range [start, end) as a list. |
| repeat(s: utf8, n: i64) → utf8 | A string repeated n times (empty for n <= 0). |
| replace(s: utf8, old: utf8, new: utf8) → utf8 | Replace every occurrence of a substring with another. |
| [reverse(xs: [T]) → [T]](functionfnreverse) | Reverse the order of a list's elements. |
| round(x: f64) → f64 | Round to the nearest integer (ties away from zero). |
| sign(x: f64) → f64 | The sign of x: 1, -1, or 0. |
| sin(x: f64) → f64 | Sine of an angle in radians. |
| [slice(xs: utf8 | [T], start: i64, end: i64) → utf8 | [T]](functionfnslice) | The half-open range [start, end) of a string's characters or a list's elements (bounds are clamped). |
| [sort(xs: [T]) → [T]](functionfnsort) | Sort a list — numerically for all-numeric lists, lexicographically for all-string lists. |
| [sort_by(xs: [T], key: fn (T) -> K) → [T]](functionfnsort_by) | Sort a list by a key function (stable). Keys must be all numeric or all strings. |
| [sort_connected(items: [T], edges: [{source, destination, ...}]) → [T]](functionfnsort_connected) | Reorder a list so that items joined by edges cluster together (recursing into children). |
| [split(s: utf8, sep: utf8) → [utf8]](functionfnsplit) | Split a string on every occurrence of a separator into a list of pieces. |
| sqrt(x: f64) → f64 | Square root. |
| starts_with(s: utf8, prefix: utf8) → bool | Whether a string begins with a prefix. |
| [sum(xs: [number]) → number](functionfnsum) | Add together every element of a non-empty homogeneous numeric list or tensor. |
| [tail(xs: [T]) → [T]](functionfntail) | Every element of a list or tensor except the first. |
| [take(xs: [T], n: i64) → [T]](functionfntake) | The first n elements of a list (fewer if the list is shorter). |
| tan(x: f64) → f64 | Tangent of an angle in radians. |
| tau() → f64 | The constant τ = 2π (≈ 6.28319). |
| [tensor(data: [number], shape: [usize]) → tensor<T>](functionfntensor) | Build a tensor from flat row-major data and a shape; the data length must equal the product of the dimensions. |
| [tensor_data(t: tensor<T>) → [T]](functionfntensor_data) | The flat row-major element data of a tensor as a list. |
| [tensor_reshape(t: tensor<T>, shape: [usize]) → tensor<T>](functionfntensor_reshape) | Reinterpret a tensor's data under a new shape; the element count must be unchanged. |
| [tensor_shape(t: tensor<T>) → [usize]](functionfntensor_shape) | The dimension sizes of a tensor as a list. |
| to_lower(s: utf8) → utf8 | Lowercase every character of a string. |
| to_upper(s: utf8) → utf8 | Uppercase every character of a string. |
| trim(s: utf8) → utf8 | Remove leading and trailing whitespace from a string. |
| trunc(x: f64) → f64 | Discard the fractional part, rounding toward zero. |
| [type_fields(target: &T) → [record]](functionfntype_fields) | Reflect a type or interface into a list of field-description records (own fields first, then inherited via extends). |
| [unique(xs: [T]) → [T]](functionfnunique) | Remove duplicate elements from a list, keeping first-seen order. |
| [values(r: record) → [T]](functionfnvalues) | The field values of a record, in the same order as keys. |
| [zip(a: [A], b: [B]) → [(A, B)]](functionfnzip) | Pair up elements of two lists by index, stopping at the shorter length. |