Skip to content

Built-in Functions

These functions are registered by the runtime and type checker, so they are available without @import(...).

FunctionReturnsPurpose
clock()f64Current process clock value
len(value)i64Length of a string or collection
type(value)strRuntime type name
str(value)strString representation
toString(value)strAlias-style string conversion
num(value)f64Convert a number or numeric string to f64
error(message)voidRaise 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.

FunctionReturns
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.

FunctionReturnsPurpose
charCodeAt(text, index)i64Unsigned byte at a zero-based index
charFromCode(code)strOne-byte string for a value from 0 through 255
slice(text, start, end)strBytes 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))
  • 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)