Built-in Functions
These functions are registered by the runtime and type checker, so they are
available without @import(...).
Runtime and conversion
Section titled “Runtime and conversion”| Function | Returns | Purpose |
|---|---|---|
clock() | f64 | Current process clock value |
len(value) | i64 | Length of a string or collection |
type(value) | str | Runtime type name |
str(value) | str | String representation |
toString(value) | str | Alias-style string conversion |
num(value) | f64 | Convert a number or numeric string to f64 |
error(message) | void | Raise a runtime error with a string message |
print(expression) is a language statement rather than an ordinary function,
but it is used with call-like syntax and is surfaced by editor tooling.
Numeric helpers
Section titled “Numeric helpers”| Function | Returns |
|---|---|
sqrt(value) | f64 |
abs(value) | f64 |
floor(value) | f64 |
ceil(value) | f64 |
pow(base, exponent) | f64 |
parseInt(text) | i64 |
parseUInt(text) | u64 |
parseFloat(text) | f64 |
The parsing functions require the entire string to be a valid value and raise a runtime error for invalid input.
Byte-oriented string helpers
Section titled “Byte-oriented string helpers”| Function | Returns | Purpose |
|---|---|---|
charCodeAt(text, index) | i64 | Unsigned byte at a zero-based index |
charFromCode(code) | str | One-byte string for a value from 0 through 255 |
slice(text, start, end) | str | Bytes in the half-open range [start, end) |
These operations use byte offsets, not Unicode code-point or grapheme indexes. Invalid codes and out-of-range bounds raise a runtime error.
print(charCodeAt("Kelvra", 0i64))print(charFromCode(77i64))print(slice("Kelvra language", 0i64, 3i64))Collection constructors
Section titled “Collection constructors”Array(values...)creates an array from zero or more values.Dict()creates an empty dictionary.Set(values...)creates a set and removes duplicate values.
Prefer a type annotation for an empty or otherwise ambiguous collection:
var values Array<i32> = Array()var lookup Dict<str, i32> = Dict()var unique Set<i32> = Set(1, 2, 2)