Lambda System Functions Reference
July 9, 2026 · View on GitHub
This document provides comprehensive documentation for all built-in system functions in Lambda Script.
Table of Contents
- Type Functions
- Mathematical Functions
- String Functions
- Collection Functions
- Date/Time Functions
- Variadic Argument Functions
- Input/Output Functions
- Error Handling
- Quick Reference Table
Type Functions
Functions for type conversion and inspection.
Type Conversion
| Function | Description | Example | Result |
|---|---|---|---|
int(x) | Convert to integer | int("42") | 42 |
int64(x) | Convert to 64-bit integer | int64("9999999999") | 9999999999 |
float(x) | Convert to float | float("3.14") | 3.14 |
decimal(x) | Convert to arbitrary precision decimal | decimal("123.456") | 123.456n |
string(x) | Convert to string | string(42) | "42" |
symbol(x) | Convert to symbol | symbol("text") | 'text' |
binary(x) | Convert to binary | binary("hello") | b'...' |
number(x) | Convert to number (int or float) | number("3.14") | 3.14 |
Type Inspection
| Function | Description | Example | Result |
|---|---|---|---|
type(x) | Get type of value | type(42) | 'int' |
name(x) | Get name of element, function, or type | name(<div>) | 'div' |
len(x) | Get length of collection or string | len([1, 2, 3]) | 3 |
// Type conversion examples
int("42") // 42
float("3.14") // 3.14
string(42) // "42"
symbol("text") // 'text'
// Type inspection
type(42) // 'int'
type("hello") // 'string'
type([1, 2, 3]) // 'array'
name(<div>) // 'div'
name(type(42)) // 'int'
len([1, 2, 3]) // 3
len("hello") // 5
Mathematical Functions
Import Styles: The
mathmodule supports three import styles:
- No import (default):
math.sqrt(x),math.pi— always available- Global import (
import math;):sqrt(x),pi— all functions available without prefix- Aliased import (
import m:math;):m.sqrt(x),m.pi— use custom prefixStandalone functions like
abs,round,floor,ceil,trunc,sign,min,max,sum,avgare always available without any prefix or import.
Rounding & Sign (global)
These functions work on both scalars and collections (element-wise).
| Function | Description | Scalar Example | Result | Vector Example | Result |
|---|---|---|---|---|---|
abs(x) | Absolute value | abs(-5) | 5 | abs([-1, 2, -3]) | [1, 2, 3] |
round(x) | Round to nearest | round(3.7) | 4 | round([1.4, 1.6]) | [1, 2] |
floor(x) | Round down | floor(3.7) | 3 | floor([1.7, 2.3]) | [1, 2] |
ceil(x) | Round up | ceil(3.2) | 4 | ceil([1.2, 2.8]) | [2, 3] |
trunc(x) | Truncate toward zero | trunc(3.7) | 3 | trunc([-3.7, 3.7]) | [-3, 3] |
sign(x) | Sign (-1, 0, 1) | sign(-5) | -1 | sign([-5, 0, 3]) | [-1, 0, 1] |
Aggregation (global)
| Function | Description | Example | Result |
|---|---|---|---|
min(a, b) | Minimum of two values | min(3, 5) | 3 |
min(vec) | Minimum in collection | min([3, 1, 2]) | 1 |
max(a, b) | Maximum of two values | max(3, 5) | 5 |
max(vec) | Maximum in collection | max([3, 1, 2]) | 3 |
argmin(vec) | Index of minimum | argmin([5, 2, 8, 1]) | 3 |
argmax(vec) | Index of maximum | argmax([5, 2, 8, 1]) | 2 |
sum(vec) | Sum of elements | sum([1, 2, 3]) | 6 |
avg(vec) | Arithmetic mean | avg([1, 2, 3]) | 2.0 |
abs(-5) // 5
round(3.7) // 4
floor(3.7) // 3
ceil(3.2) // 4
trunc(-3.7) // -3
sign(-5) // -1
min(3, 5) // 3
min([3, 1, 2]) // 1
max(3, 5) // 5
max([3, 1, 2]) // 3
argmin([5, 2, 8, 1]) // 3 (index of 1)
argmax([5, 2, 8, 1]) // 2 (index of 8)
sum([1, 2, 3, 4]) // 10
avg([1, 2, 3, 4]) // 2.5
math Module
Constants
| Constant | Description | Value |
|---|---|---|
math.pi | Pi (π) | 3.1415926536 |
math.e | Euler's number (e) | 2.7182818285 |
math.max_int | Largest compact int with exact float64 round-trip | 9007199254740991 |
Compact int is bounded to ±( - 1). Use n literals for exact integer or
decimal arithmetic beyond this compact boundary.
Trigonometric
| Function | Description | Example | Result |
|---|---|---|---|
math.sin(x) | Sine | math.sin([0, 1.57...]) | [0, 1] |
math.cos(x) | Cosine | math.cos([0, 1.57...]) | [1, 0] |
math.tan(x) | Tangent | math.tan([0, 0.785...]) | [0, 1] |
Inverse Trigonometric
| Function | Description | Example | Result |
|---|---|---|---|
math.asin(x) | Inverse sine (arcsin) | math.asin(1) | 1.5707963268 |
math.acos(x) | Inverse cosine (arccos) | math.acos(1) | 0 |
math.atan(x) | Inverse tangent (arctan) | math.atan(1) | 0.7853981634 |
math.atan2(y, x) | Two-argument arctan | math.atan2(1, 1) | 0.7853981634 |
Hyperbolic
| Function | Description | Example | Result |
|---|---|---|---|
math.sinh(x) | Hyperbolic sine | math.sinh(1) | 1.1752011936 |
math.cosh(x) | Hyperbolic cosine | math.cosh(0) | 1 |
math.tanh(x) | Hyperbolic tangent | math.tanh(1) | 0.761594156 |
Inverse Hyperbolic
| Function | Description | Example | Result |
|---|---|---|---|
math.asinh(x) | Inverse hyperbolic sine | math.asinh(1) | 0.881373587 |
math.acosh(x) | Inverse hyperbolic cosine | math.acosh(2) | 1.3169578969 |
math.atanh(x) | Inverse hyperbolic tangent | math.atanh(0.5) | 0.5493061443 |
Exponential / Logarithmic
| Function | Description | Example | Result |
|---|---|---|---|
math.exp(x) | Exponential (e^x) | math.exp([0, 1, 2]) | [1, e, e²] |
math.exp2(x) | Base-2 exponential (2^x) | math.exp2(3) | 8 |
math.expm1(x) | exp(x) - 1 (precise for small x) | math.expm1(0) | 0 |
math.log(x) | Natural logarithm | math.log([1, 2.718...]) | [0, 1] |
math.log2(x) | Base-2 logarithm | math.log2(8) | 3 |
math.log10(x) | Base-10 logarithm | math.log10([1, 10, 100]) | [0, 1, 2] |
math.log1p(x) | log(1 + x) (precise for small x) | math.log1p(0) | 0 |
Power / Root
| Function | Description | Example | Result |
|---|---|---|---|
math.pow(b, e) | Power (b^e) | math.pow(2, 10) | 1024 |
math.sqrt(x) | Square root | math.sqrt([1, 4, 9]) | [1, 2, 3] |
math.cbrt(x) | Cube root | math.cbrt(27) | 3 |
math.hypot(x, y) | Hypotenuse √(x²+y²) | math.hypot(3, 4) | 5 |
Statistical
| Function | Description | Example | Result |
|---|---|---|---|
math.mean(vec) | Alias for avg | math.mean([1, 2, 3]) | 2.0 |
math.median(vec) | Median value | math.median([1, 3, 2]) | 2 |
math.variance(vec) | Population variance | math.variance([1, 2, 3]) | 0.666... |
math.deviation(vec) | Standard deviation | math.deviation([1, 2, 3]) | 0.816... |
math.quantile(vec, p) | p-th quantile | math.quantile([1,2,3,4], 0.5) | 2.5 |
math.prod(vec) | Product of elements | math.prod([2, 3, 4]) | 24 |
math.cumsum(vec) | Cumulative sum | math.cumsum([1, 2, 3]) | [1, 3, 6] |
math.cumprod(vec) | Cumulative product | math.cumprod([1, 2, 3]) | [1, 2, 6] |
math.dot(a, b) | Dot product | math.dot([1,2,3], [4,5,6]) | 32 |
math.norm(vec) | Euclidean norm | math.norm([3, 4]) | 5 |
Random
Pure functional pseudo-random number generator using the SplitMix64 algorithm. Takes an integer seed and returns a list [value, new_seed] where value is a float in [0.0, 1.0).
| Function | Description | Example | Result |
|---|---|---|---|
math.random(seed) | Generate random float and new seed | let x, s = math.random(42) | [0.7415..., -7046...] |
// math module examples
math.pi // 3.1415926536
math.e // 2.7182818285
math.sin([0, 3.14159/2]) // [0, 1]
math.cos([0, 3.14159/2]) // [1, 0]
math.asin(1) // 1.5707963268 (π/2)
math.atan2(1, 1) // 0.7853981634 (π/4)
math.sinh(1) // 1.1752011936
math.exp2(3) // 8
math.log2(8) // 3
math.pow(2, 10) // 1024
math.cbrt(27) // 3
math.hypot(3, 4) // 5
// statistical
math.mean([1, 2, 3, 4]) // 2.5
math.median([1, 3, 2, 4, 5]) // 3
math.variance([1, 2, 3]) // 0.666...
math.deviation([1, 2, 3]) // 0.816...
math.quantile([1, 2, 3, 4], 0.5) // 2.5
math.prod([2, 3, 4]) // 24
math.cumsum([1, 2, 3, 4]) // [1, 3, 6, 10]
math.cumprod([1, 2, 3, 4]) // [1, 2, 6, 24]
math.dot([1, 2, 3], [4, 5, 6]) // 32
math.norm([3, 4]) // 5
// random
let x, seed1 = math.random(42)
x // 0.7415648788 (float in [0.0, 1.0))
let x2, seed2 = math.random(seed1)
let dice = floor(x * 6) + 1 // random 1-6
String Functions
Functions for string manipulation. replace, split, and find accept either a plain string or a named string pattern as the match argument.
String Pattern Recap
String patterns are defined in the type system (see Lambda_Type.md § String Patterns) and can be used as arguments to string functions:
string digits = \d+ // one or more digits
string ws = \s+ // one or more whitespace chars
string word = \w+ // word characters
slice(str, start, end?)
Extract a UTF-8 character slice from a string. slice(str, start, end) uses a
zero-based start index inclusive and end index exclusive ([start, end));
slice(str, start) slices from start to the end. Negative indices count from
the end, and out-of-range indices are clamped.
Range subscript syntax is also supported: str[a to b] returns characters
a through b, inclusive. In other words, str[a to b] is equivalent to
slice(str, a, b + 1).
| Function | Description | Example | Result |
|---|---|---|---|
slice(str, i, j) | Characters [i, j) | slice("hello", 1, 4) | "ell" |
slice(str, i) | Characters [i, end) | slice("hello", 2) | "llo" |
str[i to j] | Characters i through j, inclusive | "hello"[1 to 3] | "ell" |
slice("hello", 0, 2) // "he"
slice("hello", 2) // "llo"
slice("café", 2, 4) // "fé" — UTF-8 character indices
"hello"[0 to 4] // "hello"
"hello"[1 to 3] // "ell"
replace(str, pattern_or_string, replacement)
Replace all occurrences of a pattern or substring in a string. Returns a new string.
| Function | Description | Example | Result |
|---|---|---|---|
replace(str, pattern, repl) | Replace all pattern matches | replace("a1b2", \d, "X") | "aXbX" |
replace(str, string, repl) | Replace all substring matches | replace("abc", "b", "X") | "aXc" |
string digit = \d
string digits = \d+
string ws = \s+
replace("a1b2c3", digit, "X") // "aXbXcX"
replace("a1b22c333", digits, "N") // "aNbNcN"
replace("hello world", ws, " ") // "hello world"
replace("no-digits", digit, "X") // "no-digits" (no match → unchanged)
replace("a1b2", digit, "") // "ab" (delete matches)
replace("abc", "b", "") // "ac" (plain string delete)
split(str, pattern_or_string, keep_delimiters?)
Split a string by pattern or substring. Returns an array of substrings.
| Function | Description | Example | Result |
|---|---|---|---|
split(str, pattern) | Split by pattern | split("a1b2", \d) | ["a", "b", ""] |
split(str, string) | Split by substring | split("a,b,c", ",") | ["a", "b", "c"] |
split(str, sep, true) | Split, keep delimiters | split("a1b2", \d, true) | ["a","1","b","2",""] |
string digit = \d
string digits = \d+
string ws = \s+
split("a1b2c3", digit) // ["a", "b", "c", ""]
split("hello world", ws) // ["hello", "world"]
split("a1b22c333", digits) // ["a", "b", "c", ""]
split("no-match", digit) // ["no-match"]
split("a1b2c3", digit, true) // ["a", "1", "b", "2", "c", "3", ""] — keep delimiters
split("a,b,c", ",", true) // ["a", ",", "b", ",", "c"] — works with strings too
join(strs, separator)
Join a list of strings with a separator. Returns a string.
| Function | Description | Example | Result |
|---|---|---|---|
join(strs, sep) | Join with separator | join(["a", "b", "c"], ", ") | "a, b, c" |
join(strs, "") | Concatenate | join(["hello", "world"], "") | "helloworld" |
join(["a", "b", "c"], ", ") // "a, b, c"
join(["hello"], ", ") // "hello"
join(["x", "y"], "-") // "x-y"
find(str, pattern_or_string)
Find all occurrences of a pattern or substring. Returns a list of match maps {value, index}.
| Function | Description | Example | Result |
|---|---|---|---|
find(str, pattern) | Find all pattern matches | find("a1b22", \d+) | [{value:"1",index:1}, ...] |
find(str, string) | Find all substring matches | find("abab", "ab") | [{value:"ab",index:0}, ...] |
Each match is a map with:
value— the matched substringindex— the start position (0-based) in the source string
string digits = \d+
string words = \w+
find("a1b22c333", digits)
// [{value: "1", index: 1}, {value: "22", index: 3}, {value: "333", index: 6}]
find("hello world", words)
// [{value: "hello", index: 0}, {value: "world", index: 6}]
find("hello world hello", "lo")
// [{value: "lo", index: 3}, {value: "lo", index: 14}]
find("no-match", digits)
// [] (empty array)
// Extract just matching values via pipe
find("a1b22", digits) | ~.value // ["1", "22"]
contains(str, substring)
Check if a string contains a substring. Returns true or false. Also works on collections (see Collection Functions).
| Function | Description | Example | Result |
|---|---|---|---|
contains(str, sub) | Check substring presence | contains("hello", "ell") | true |
contains("hello world", "world") // true
contains("hello world", "xyz") // false
contains("abcdef", "cd") // true
contains("", "a") // false
starts_with(str, prefix)
Check if a string starts with a given prefix. Returns true or false.
| Function | Description | Example | Result |
|---|---|---|---|
starts_with(str, prefix) | Check prefix | starts_with("hello", "hel") | true |
starts_with("hello world", "hello") // true
starts_with("hello world", "world") // false
starts_with("abc", "") // true
starts_with("abc", "abcd") // false
ends_with(str, suffix)
Check if a string ends with a given suffix. Returns true or false.
| Function | Description | Example | Result |
|---|---|---|---|
ends_with(str, suffix) | Check suffix | ends_with("hello", "llo") | true |
ends_with("hello world", "world") // true
ends_with("hello world", "hello") // false
ends_with("abc", "") // true
ends_with("abc", "abcd") // false
index_of(str, substring)
Return the index of the first occurrence of a substring (-1 if not found). Also works on collections (see Collection Functions).
| Function | Description | Example | Result |
|---|---|---|---|
index_of(str, sub) | First occurrence index | index_of("hello", "ll") | 2 |
index_of("hello world", "world") // 6
index_of("hello world", "xyz") // -1
index_of("abcabc", "bc") // 1
last_index_of(str, substring)
Return the index of the last occurrence of a substring (-1 if not found). Also works on collections (see Collection Functions).
| Function | Description | Example | Result |
|---|---|---|---|
last_index_of(str, sub) | Last occurrence index | last_index_of("abcabc", "bc") | 4 |
last_index_of("abcabc", "abc") // 3
last_index_of("hello", "l") // 3
last_index_of("hello", "xyz") // -1
trim(str) / trim_start(str) / trim_end(str)
Remove whitespace from a string.
| Function | Description | Example | Result |
|---|---|---|---|
trim(str) | Remove leading and trailing whitespace | trim(" hello ") | "hello" |
trim_start(str) | Remove leading whitespace | trim_start(" hello ") | "hello " |
trim_end(str) | Remove trailing whitespace | trim_end(" hello ") | " hello" |
trim(" hello world ") // "hello world"
trim_start(" hello ") // "hello "
trim_end(" hello ") // " hello"
trim("\t\n hello \n") // "hello"
upper(str) / lower(str)
Convert string case. Unicode-aware.
| Function | Description | Example | Result |
|---|---|---|---|
upper(str) | Convert to uppercase | upper("hello") | "HELLO" |
lower(str) | Convert to lowercase | lower("HELLO") | "hello" |
upper("hello") // "HELLO"
lower("HELLO") // "hello"
upper("café") // "CAFÉ"
lower("Straße") // "straße"
normalize(str)
Normalize a string (Unicode normalization).
url_resolve(base, relative)
Resolve a relative URL against a base URL.
url_resolve("https://example.com/a/b", "../c") // "https://example.com/c"
url_resolve("https://example.com/a/", "page.html") // "https://example.com/a/page.html"
ord(str)
Return the Unicode code point (int) of the first character. Works on both strings and symbols.
ord("A") // 65
ord("é") // 233
ord("😀") // 128512
ord('A') // 65 (symbol input)
ord("hello") // 104 (first character 'h')
ord("") // 0 (empty string has no first character)
chr(int)
Return a 1-character string from a Unicode code point.
chr(65) // "A"
chr(233) // "é"
chr(128512) // "😀"
chr(-1) // null (out of range)
Round-trip:
chr(ord("Z")) // "Z"
ord(chr(65)) // 65
Collection Functions
Functions for working with arrays and other collections.
Query & Test
| Function | Description | Example | Result |
|---|---|---|---|
len(x) | Length of collection | len([1, 2, 3]) | 3 |
contains(vec, val) | Check if element exists | contains([1, 2, 3], 2) | true |
index_of(vec, val) | Index of first match (-1 if none) | index_of([1, 2, 3], 2) | 1 |
last_index_of(vec, val) | Index of last match (-1 if none) | last_index_of([1, 2, 1], 1) | 2 |
all(vec) | All elements truthy? | all([true, true, false]) | false |
any(vec) | Any element truthy? | any([false, false, true]) | true |
contains, index_of, and last_index_of work on lists, typed arrays (int, float), maps (key existence), and elements (children). They also work on strings (see String Functions).
// List membership
contains([1, 2, 3], 2) // true
contains(["a", "b", "c"], "d") // false
// Index search
index_of([10, 20, 30, 20], 20) // 1
last_index_of([10, 20, 30, 20], 20) // 3
index_of([1, 2, 3], 99) // -1
// Map key existence
contains({name: "Alice", age: 30}, 'name') // true
contains({x: 1, y: 2}, 'z') // false
Extraction
| Function | Description | Example | Result |
|---|---|---|---|
slice(vec, i, j) | Extract slice [i, j) | slice([1,2,3,4], 1, 3) | [2, 3] |
slice(vec, i) | Extract slice [i, end) | slice([1,2,3,4], 2) | [3, 4] |
take(vec, n) | First n elements | take([1, 2, 3], 2) | [1, 2] |
drop(vec, n) | Drop first n elements | drop([1, 2, 3], 1) | [2, 3] |
Transformation
| Function | Description | Example | Result |
|---|---|---|---|
reverse(vec) | Reverse order | reverse([1, 2, 3]) | [3, 2, 1] |
sort(vec) | Sort ascending | sort([3, 1, 2]) | [1, 2, 3] |
sort(vec, 'desc') | Sort descending | sort([1, 2, 3], 'desc') | [3, 2, 1] |
sort(vec, fn) | Sort by key function | sort(users, ~.age) | Sorted by age |
sort(vec, options) | Sort with options map | sort(users, {dir: 'desc', by: ~.age}) | Sorted by age desc |
unique(vec) | Remove duplicates (preserves order) | unique([1, 2, 2, 3]) | [1, 2, 3] |
set(vec) | Remove duplicates | set([1, 1, 2, 2, 3]) | [1, 2, 3] |
zip(v1, v2) | Pair elements | zip([1, 2], [3, 4]) | [(1, 3), (2, 4)] |
Construction
| Function | Description | Example | Result |
|---|---|---|---|
fill(n, value) | Vector of n copies | fill(3, 5) | [5, 5, 5] |
range(start, end, step) | Range with step | range(0, 10, 2) | [0, 2, 4, 6, 8] |
Reduction
| Function | Description | Example | Result |
|---|---|---|---|
reduce(vec, fn) | Reduce with binary function | reduce([1,2,3], (a,b) => a+b) | 6 |
Reduce a collection to a single value by applying a binary function cumulatively. Uses the first element as the initial accumulator.
slice([1, 2, 3, 4], 1, 3) // [2, 3]
slice([1, 2, 3, 4], 2) // [3, 4]
take([1, 2, 3, 4], 2) // [1, 2]
drop([1, 2, 3, 4], 2) // [3, 4]
all([true, true, false]) // false
any([false, false, true]) // true
reverse([1, 2, 3]) // [3, 2, 1]
sort([3, 1, 2]) // [1, 2, 3]
sort([1, 2, 3], 'desc') // [3, 2, 1]
// Sort by key function
let users = [{name: "Bob", age: 30}, {name: "Alice", age: 25}]
sort(users, ~.age) // sorted by age ascending
sort(users, {dir: 'desc', by: ~.age}) // sorted by age descending
unique([1, 2, 2, 3, 3]) // [1, 2, 3]
zip([1, 2], ["a", "b"]) // [(1, "a"), (2, "b")]
fill(3, 0) // [0, 0, 0]
range(0, 10, 2) // [0, 2, 4, 6, 8]
reduce([1, 2, 3, 4], (a, b) => a + b) // 10 (sum)
reduce([1, 2, 3, 4, 5], (a, b) => a * b) // 120 (product)
Note:
reducerequires at least one element. If only one element, it is returned directly without calling the function.
Date/Time Functions
Functions for date and time operations.
Current Time
| Function | Description | Example | Result |
|---|---|---|---|
datetime() | Current date and time | datetime() | t'2025-01-23T14:30:00' |
datetime(x) | Parse as datetime | datetime("2025-01-01") | t'2025-01-01' |
today() | Current date | today() | t'2025-01-23' |
now() | Current timestamp (proc) | now() | t'2025-01-23T14:30:00' |
justnow() | Time when current script evaluation started | justnow() | t'14:30:00' |
Date/Time Extraction
| Function | Description | Example | Result |
|---|---|---|---|
date(dt) | Extract date part | date(t'2025-01-01T14:30') | t'2025-01-01' |
time(dt) | Extract time part | time(t'2025-01-01T14:30') | t'14:30:00' |
datetime() // Current date and time
today() // Current date
justnow() // Current time
date(t'2025-01-01T14:30') // t'2025-01-01'
time(t'2025-01-01T14:30') // t'14:30:00'
Variadic Argument Functions
Functions for accessing variable arguments inside variadic functions.
| Function | Description | Example | Result |
|---|---|---|---|
varg() | All variadic arguments | varg() | List of args |
varg(n) | nth variadic argument (0-indexed) | varg(0) | First arg |
// Define a variadic function
fn sum_all(...) => sum(varg())
fn first_arg(...) => varg(0)
fn count_args(...) => len(varg())
// Use the functions
sum_all(1, 2, 3, 4) // 10
first_arg("a", "b", "c") // "a"
count_args(1, 2, 3) // 3
Input/Output Functions
Lambda Script provides comprehensive support for file I/O with unified path/URL handling and multiple document formats.
Unified Path and URL Handling
Lambda uses Path literals with unified syntax for both local files and remote URLs:
// Local paths
let local = /.data.'config.json' // Relative path
let absolute = /Users.name.project // Absolute path
// Remote URLs
let api = https.'api.example.com'.data // HTTPS URL
let file_url = /path.to.file // File URL
// All work uniformly with I/O functions
let data = input(local)
let remote = input(api)
Pure I/O Functions
These functions can be used anywhere (in both fn and pn functions).
input(target) / input(target, format)
Parse content from a file path or URL.
| Function | Description | Example |
|---|---|---|
input(target) | Parse target (auto-detect format) | input(/.'data.json') |
input(target, format) | Parse target with specified format | input("data.json", 'json') |
Supported Input Formats: json, xml, html, yaml, toml, markdown, csv, latex, rtf, pdf, css, ini, math
| Format | Description | Example |
|---|---|---|
| JSON | JavaScript Object Notation | input(/.'data.json', 'json') |
| XML | Extensible Markup Language | input(/.'config.xml', 'xml') |
| HTML | HyperText Markup Language | input(/.'page.html', 'html') |
| YAML | YAML Ain't Markup Language | input(/.'config.yaml', 'yaml') |
| TOML | Tom's Obvious Minimal Language | input(/.'config.toml', 'toml') |
| Markdown | Markdown markup | input(/.'doc.md', 'markdown') |
| CSV | Comma-Separated Values | input(/.'data.csv', 'csv') |
| LaTeX | LaTeX markup | input(/.'doc.tex', 'latex') |
| RTF | Rich Text Format | input(/.'doc.rtf', 'rtf') |
| Portable Document Format | input(/.'doc.pdf', 'pdf') | |
| CSS | Cascading Style Sheets | input(/.'style.css', 'css') |
| INI | Configuration files | input(/.'config.ini', 'ini') |
| Math | Mathematical expressions | input(/.'formula.txt', 'math') |
Input Function Usage:
// Basic input parsing with Path literals
let data = input(/.'file.json', 'json')
let config = input(/.'settings.yaml', 'yaml')
// Input from URLs
let api_data = input(https.'api.example.com'.'users.json')
// Input with options map
let math_expr = input(/.'formula.txt', {type: 'math', flavor: 'latex'})
let csv_data = input(/.'data.csv', {type: 'csv', delimiter: ','})
// Auto-detection (based on file extension)
let auto_data = input(/.'document.md') // Automatically detects Markdown
parse(str) / parse(str, format)
Parse a string into Lambda data structures. Like input() but operates on string content instead of file paths/URLs.
| Function | Description | Example |
|---|---|---|
parse(str) | Parse string (auto-detect format) | parse("{\"x\": 1}") |
parse(str, format) | Parse string with specified format | parse(str, 'json') |
Supported Formats: Same as input() — json, xml, html, yaml, toml, markdown, csv, latex, css, ini, math
// Parse JSON string
let data^err = parse("{\"name\": \"Alice\", \"age\": 30}", 'json')
data.name // "Alice"
// Auto-detect JSON from content
let data2^err = parse("{\"x\": 1}")
data2.x // 1
// Parse with options map
let expr^err = parse("x^2 + y", {type: 'math', flavor: 'latex'})
// Parse CSV from string
let csv^err = parse("name,age\nAlice,30\nBob,25", 'csv')
Note:
parse()can raise errors. Uselet result^err = parse(...)for error-safe handling.
exists(target)
Check if a file, directory, or URL target exists. Returns true or false.
let file_exists = exists(/.'config.json')
let dir_exists = exists(/.data)
if exists(/.'cache.json') {
let cached = input(/.'cache.json')
}
format(data) / format(data, type)
Format data as a string in various formats. This is a pure function that returns a string.
| Function | Description | Example |
|---|---|---|
format(data) | Format data as Lambda representation | format(obj) |
format(data, type) | Format data as specified type | format(obj, 'json') |
// Format data as different types
let json_str = format(data, 'json')
let yaml_str = format(data, 'yaml')
let xml_str = format(data, 'xml')
// Format with options
let pretty_json = format(data, {type: 'json', indent: 2})
let compact_json = format(data, {type: 'json', compact: true})
Procedural I/O Functions
Functions that have side effects (I/O, state changes). These are only available in procedural functions (pn).
Overview
| Function | Description | Example |
|---|---|---|
print(args...) | Print values to console | print("x =", x) |
output(data, target) | Write data to file/URL | output(data, /.'out.json') |
output(data, target, {mode: "append"}) | Append data to file/URL | output(line, /.'log.txt', {mode: "append"}) |
io.copy(src, dst) | Copy file or directory | io.copy(/.'a.txt', /.'b.txt') |
io.move(src, dst) | Move/rename file or directory | io.move(/.old, /.new) |
io.delete(target) | Delete file or directory | io.delete(/.'temp.txt') |
io.mkdir(path) | Create directory | io.mkdir(/.data) |
io.touch(path) | Create empty file or update timestamp | io.touch(/.'flag.txt') |
io.symlink(target, link) | Create symbolic link | io.symlink(/.src, /.link) |
io.chmod(path, mode) | Change file permissions | io.chmod(/.'script.sh', "755") |
io.rename(src, dst) | Rename file or directory | io.rename(/.'a.txt', /.'b.txt') |
io.fetch(url, options) | HTTP fetch with options | io.fetch(https.'api.example.com', {method: 'POST'}) |
cmd(command, args...) | Execute shell command | cmd("ls", "-la") |
clock() | Monotonic clock in seconds | clock() |
print(args...)
Prints values to the console (stdout). Arguments are stringified and joined with a single space separator.
print("Hello, world!")
print(42)
print([1, 2, 3])
print("x =", 42)
output(data, target) / output(data, target, format)
Writes data to a file or URL. The format can be auto-detected from the target extension or explicitly specified.
pn save_data() {
let data = {name: "Alice", age: 30, scores: [95, 87, 92]}
// Using Path literals
output(data, /.'result.json') // Writes JSON
output(data, /.'result.yaml') // Writes YAML
output(data, /.'result.xml') // Writes XML
// Explicit format specification
output(data, /.'data.txt', 'json') // Force JSON format
output(data, /.'data.out', 'yaml') // Force YAML format
// With options
output(data, /.'pretty.json', {type: 'json', indent: 4})
}
Supported output formats:
| Format | Extension | Description |
|---|---|---|
json | .json | JSON format |
yaml | .yaml, .yml | YAML format |
xml | .xml | XML format |
html | .html, .htm | HTML format |
markdown | .md | Markdown format |
text | .txt | Plain text |
toml | .toml | TOML format |
ini | .ini | INI configuration format |
Output Function
Lambda uses output(...) for file writing in procedural functions.
Write/Truncate
output(data, target) writes data to a target, truncating existing content:
pn generate_report() {
let report = {title: "Monthly Report", date: today(), items: [...]}
output(report, /.reports.'monthly.json')
}
Append
Pass {mode: "append"} as the third argument to append:
pn log_event(event) {
let entry = format({time: now(), event: event}, 'json')
output(entry, /.logs.'events.jsonl', {mode: "append"})
}
pn process_items(items) {
for item in items {
output(process(item), /.'output.txt', {mode: "append"})
}
}
io Module Functions
The io module provides procedural functions for file system operations.
Import Styles: The
iomodule supports three import styles:
- No import (default):
io.copy(/.a, /.b)— always available- Global import (
import io;):copy(/.a, /.b)— all functions without prefix- Aliased import (
import f:io;):f.copy(/.a, /.b)— use custom prefix
io.copy(source, destination)
Copy a file or directory to a new location.
pn backup_config() {
io.copy(/.'config.json', /.backup.'config.json')
io.copy(/.data, /.backup.data) // Copy directory recursively
}
io.move(source, destination)
Move or rename a file or directory.
pn archive_logs() {
io.move(/.logs.'current.log', /.logs.archive.'2024-01.log')
}
io.delete(target)
Delete a file or directory.
pn cleanup() {
io.delete(/.'temp.txt')
io.delete(/.cache) // Delete directory recursively
}
io.mkdir(path)
Create a directory (and parent directories if needed).
pn setup_project() {
io.mkdir(/.src)
io.mkdir(/.tests)
io.mkdir(/.docs.api) // Creates parent dirs too
}
io.touch(path)
Create an empty file or update its modification timestamp.
pn mark_complete() {
io.touch(/.build.'.done')
}
io.symlink(target, link_path)
Create a symbolic link.
pn setup_links() {
io.symlink(/.config.'production.json', /.'config.json')
}
io.chmod(path, mode)
Change file permissions (Unix-style).
pn make_executable() {
io.chmod(/.scripts.'deploy.sh', "755")
io.chmod(/.'secrets.env', "600")
}
io.rename(source, destination)
Rename a file or directory (alias for move within same directory).
pn rename_file() {
io.rename(/.'draft.txt', /.'final.txt')
}
io.fetch(url, options)
Perform HTTP requests with full control over method, headers, and body.
pn api_operations() {
// GET request
let data = io.fetch(https.'api.example.com'.users, {
method: 'GET',
headers: {Authorization: "Bearer token123"}
})
// POST request
let result = io.fetch(https.'api.example.com'.users, {
method: 'POST',
headers: {Content-Type: "application/json"},
body: format({name: "Alice", email: "alice@example.com"}, 'json')
})
}
cmd(command, args...)
Execute a shell command and return the result.
pn run_commands() {
let files = cmd("ls", "-la")
let date = cmd("date", "+%Y-%m-%d")
// With multiple arguments
cmd("git", "commit", "-m", "Update files")
}
clock()
Returns the current value of a monotonic clock as a float in seconds. Useful for measuring elapsed time in benchmarks and performance profiling. The returned value has nanosecond precision and is not related to wall-clock time.
pn benchmark() {
var t0 = clock()
// ... work to measure ...
var t1 = clock()
var elapsed_ms = (t1 - t0) * 1000.0
print("Elapsed: " + string(elapsed_ms) + " ms")
}
Error Handling
Functions for creating and handling errors.
| Function | Description | Example | Result |
|---|---|---|---|
error(msg) | Create error value | error("Invalid input") | Error |
// Create an error
error("Something went wrong")
// Error handling in expressions
let result = if (x == 0) error("Division by zero") else (y / x)
// Check for error
if (result is error) {
print("Error occurred")
}
Quick Reference Table
Type Functions
| Function | Args | Description |
|---|---|---|
len | 1 | Get length |
type | 1 | Get type |
int | 1 | Convert to int |
int64 | 1 | Convert to int64 |
float | 1 | Convert to float |
decimal | 1 | Convert to decimal |
string | 1 | Convert to string |
symbol | 1 | Convert to symbol |
binary | 1 | Convert to binary |
number | 1 | Convert to number |
Math Functions
| Function | Args | Description |
|---|---|---|
abs | 1 | Absolute value |
round | 1 | Round to nearest |
floor | 1 | Round down |
ceil | 1 | Round up |
sign | 1 | Sign (-1, 0, 1) |
trunc | 1 | Truncate toward zero |
math.sqrt | 1 | Square root |
math.cbrt | 1 | Cube root |
math.hypot | 2 | Hypotenuse √(x²+y²) |
math.pow | 2 | Power (b^e) |
math.log | 1 | Natural log |
math.log2 | 1 | Base-2 log |
math.log10 | 1 | Base-10 log |
math.log1p | 1 | log(1 + x) |
math.exp | 1 | Exponential (e^x) |
math.exp2 | 1 | Base-2 exponential |
math.expm1 | 1 | exp(x) - 1 |
math.sin | 1 | Sine |
math.cos | 1 | Cosine |
math.tan | 1 | Tangent |
math.asin | 1 | Inverse sine |
math.acos | 1 | Inverse cosine |
math.atan | 1 | Inverse tangent |
math.atan2 | 2 | Two-arg arctan |
math.sinh | 1 | Hyperbolic sine |
math.cosh | 1 | Hyperbolic cosine |
math.tanh | 1 | Hyperbolic tangent |
math.asinh | 1 | Inverse hyp. sine |
math.acosh | 1 | Inverse hyp. cosine |
math.atanh | 1 | Inverse hyp. tangent |
math.pi | - | Pi (π) constant |
math.e | - | Euler's number constant |
math.max_int | - | Maximum compact int constant |
Aggregation Functions (Global)
| Function | Args | Description |
|---|---|---|
min | 1-2 | Minimum |
max | 1-2 | Maximum |
argmin | 1 | Index of min |
argmax | 1 | Index of max |
sum | 1 | Sum |
avg | 1 | Average |
Statistical Functions (math Module)
| Function | Args | Description |
|---|---|---|
math.mean | 1 | Mean |
math.median | 1 | Median |
math.variance | 1 | Variance |
math.deviation | 1 | Std deviation |
math.quantile | 2 | Quantile |
math.prod | 1 | Product |
math.cumsum | 1 | Cumulative sum |
math.cumprod | 1 | Cumulative product |
math.dot | 2 | Dot product |
math.norm | 1 | Euclidean norm |
math.random | 0-2 | Random number |
String Functions
| Function | Args | Description |
|---|---|---|
contains | 2 | Check if string contains substring |
starts_with | 2 | Check if string starts with prefix |
ends_with | 2 | Check if string ends with suffix |
index_of | 2 | Index of first substring occurrence |
last_index_of | 2 | Index of last substring occurrence |
trim | 1 | Remove leading/trailing whitespace |
trim_start | 1 | Remove leading whitespace |
trim_end | 1 | Remove trailing whitespace |
upper | 1 | Convert to uppercase |
lower | 1 | Convert to lowercase |
replace | 3 | Replace pattern/substring in string |
split | 2-3 | Split string by pattern/substring |
join | 2 | Join list of strings with separator |
find | 2 | Find all pattern/substring matches |
ord | 1 | Unicode code point of first character |
chr | 1 | Character from Unicode code point |
normalize | 1 | Normalize string |
url_resolve | 2 | Resolve relative URL against base |
Collection Functions
| Function | Args | Description |
|---|---|---|
contains | 2 | Check element membership |
index_of | 2 | Index of first matching element |
last_index_of | 2 | Index of last matching element |
slice | 2 or 3 | Extract slice; 2-arg form slices to end |
set | 1+ | Remove duplicates |
all | 1 | All truthy |
any | 1 | Any truthy |
reverse | 1 | Reverse order |
sort | 1-2 | Sort (dir, key fn, or options map) |
unique | 1 | Unique elements |
take | 2 | Take first n |
drop | 2 | Drop first n |
zip | 2 | Zip vectors |
fill | 2 | Fill vector |
range | 3 | Range with step |
reduce | 2 | Reduce with binary fn |
Date/Time Functions
| Function | Args | Description |
|---|---|---|
datetime | 0-1 | Date and time |
date | 1 | Extract date |
time | 1 | Extract time |
today | 0 | Current date (proc) |
now | 0 | Current time (proc) |
justnow | 0 | Time only |
I/O Functions (Pure)
| Function | Args | Description |
|---|---|---|
input | 1-2 | Parse file/URL |
parse | 1-2 | Parse string content |
exists | 1 | Check if target exists |
format | 1-2 | Format data as string |
I/O Functions (Procedural)
| Function | Args | Description |
|---|---|---|
print | 0+ | Print values to console |
output | 2-3 | Write to file/URL |
io.copy | 2 | Copy file/directory |
io.move | 2 | Move file/directory |
io.delete | 1 | Delete file/directory |
io.mkdir | 1 | Create directory |
io.touch | 1 | Create/update file |
io.symlink | 2 | Create symbolic link |
io.chmod | 2 | Change permissions |
io.rename | 2 | Rename file/directory |
io.fetch | 2 | HTTP request |
cmd | 1+ | Shell command |
clock | 0 | Monotonic clock (seconds) |
Other Functions
| Function | Args | Description |
|---|---|---|
error | 1 | Create error |
varg | 0-1 | Variadic args |