Built-in Functions

Quick Reference

Core: print, len, sum, range, error

Type conversion: num, int, str, bool

Math: abs, min, max, floor, ceil, round, sign, trunc, is_nan

Search: find (works on both strings and arrays)

Arrays: push, pop, set, concat, sort, reverse, slice

Objects: keys, values, dict, merge, get

Type checking: type

Examples

// Core utilities
print("Hello, World!")
items = [1, 2, 3, 4, 5]
print(len(items))        // 5
print(sum(items))        // 15
nums = range(0, 10, 2)   // [0, 2, 4, 6, 8]

// Type conversion
i = int("42")            // 42
s = str(123)             // "123"
b = bool(1)              // true

// Basic math (built-in)
print(abs(-5))           // 5
print(floor(3.7))        // 3
print(min(1, 2))         // 1
print(is_nan(0 / 0))    // true

// Search
idx = find([10, 20, 30], 20)    // 1
pos = find("hello", "ll")       // 2

// Arrays — all return NEW values, they do not mutate
items = [1, 2, 3]
updated = push(items, 4)        // [1, 2, 3, 4] (items is unchanged)
result = pop(items)              // {array = [1, 2], value = 3}
replaced = set(items, 0, 99)    // [99, 2, 3] (items is unchanged)
sorted = sort([3, 1, 4])        // [1, 3, 4]
rev = reverse([1, 2, 3])        // [3, 2, 1]
sub = slice([1, 2, 3, 4], 1, 3) // [2, 3]

// Objects
person = { name = "Alice", age = 30 }
print(keys(person))      // ["name", "age"]
print(values(person))    // ["Alice", 30]

// String functions require import
import split, join, contains from string
parts = split("a,b,c", ",")    // ["a", "b", "c"]
joined = join(parts, "-")       // "a-b-c"
has = contains("hello", "ell") // true

What Requires Import

Functions that require an explicit import:

CategoryFunctionsModule
Trigonometrysin, cos, tan, asin, acos, atan, atan2math
Powers/Logssqrt, pow, exp, logmath
Hyperbolicsinh, cosh, tanhmath
Math extrashypot, clamp, lerp, log10, log2, cbrt, gcd, lcmmath
Complexreal, imag, conj, argcomplex
Stringssplit, join, contains, upper, lower, trimstring
Randomrand, randn, randint, choice, shuffle, sample, srand, srandn, srandintrandom
// Math functions require import
import sin, cos, sqrt, PI from math
print(sin(PI / 2))       // 1
print(sqrt(16))          // 4

// Complex accessors require import
import real, imag from complex
z = 3 + 4i
print(real(z))           // 3
print(imag(z))           // 4

Array Functions

All array functions return new values — they never mutate the original.

items = [1, 2, 3]

// Add/remove elements
updated = push(items, 4)          // [1, 2, 3, 4]
result = pop(items)                // {array = [1, 2], value = 3}

// Replace element at index
changed = set(items, 1, 99)       // [1, 99, 3]

// Sort, reverse, slice, concat
sorted = sort([3, 1, 4, 1, 5])   // [1, 1, 3, 4, 5]
rev = reverse([1, 2, 3])          // [3, 2, 1]
sub = slice([10, 20, 30, 40], 1, 3) // [20, 30]
all = concat([1, 2], [3, 4])      // [1, 2, 3, 4]

// Search
idx = find([10, 20, 30], 20)      // 1
pos = find("hello", "ll")         // 2

// Length and sum
n = len(items)                     // 3
s = sum(items)                     // 6

Object Functions

dict(keys, values)

Create a record from parallel arrays of keys and values:

scores = dict(["math", "sci"], [95, 88])
print(scores.math)    // 95

merge(a, b)

Combine two records. Fields from b override a when keys collide:

base = {x = 1, y = 2}
extra = {y = 3, z = 4}
merged = merge(base, extra)
print(merged.x)  // 1
print(merged.y)  // 3 (overridden by b)
print(merged.z)  // 4

The type checker knows the exact fields of the merged result — accessing a field not in either record is a compile error.

get(obj, key)

Safe dynamic field lookup. Returns a record {ok, value} — no runtime trap on missing fields:

point = {x = 10, y = 20}

result = get(point, "x")
print(result.ok)     // 1 (true)
print(result.value)  // 10

missing = get(point, "z")
print(missing.ok)    // 0 (false)
print(missing.value) // 0

Use get() when you don't know at compile time whether a field exists. Use dot access (obj.field) when the field is statically known.

Notes

  • Operators are primary: Use +, -, *, /, % for scalar arithmetic; .+, .-, .*, ./ for element-wise array operations
  • Indexing is built-in: Access array elements with xs[i] and object fields with obj.field
  • Mapping is built-in: Transform arrays with indexed mapping: out[i] = f(xs[i])
  • Filtering: Use import filter from array for predicate-based filtering: filter(xs, fn (x) = x > 0)
  • Imports for more: Use import from array, import from linalg, etc. for additional functions