std/core
Always in scope — no import required.
The core data types with their methods, scalar math, and the global utility and transport functions.
The Array type and its utilities.
An Array is an ordered, growable collection of values of any type, written with the #[1, 2, 3] literal. Its methods index and slice, add and remove elements, and transform, filter, and fold — most returning arrays so calls chain.
Ordered collection of values. Construct with #[1, 2, 3] or Array(1, 2, 3).
Constructor
Section titled “Constructor”fn Array(...items) -> ArrayCreates an array from individual values. Prefer the #[1, 2, 3] literal syntax. This constructor is kept for compatibility.
Example:
Array(1, 2, 3) returns #[1, 2, 3]
Parameters:
items(Array) — variadic values to collect into the array
Returns: Array — a new array of the given values
length
Section titled “length”fn length() -> NumberReturns the number of elements.
Returns: Number — the element count
fn push(value: any) -> ArrayAdds an element to the end of the array.
Parameters:
value(Any) — the element to add
Returns: Array — the array, for chaining
fn pop()Removes and returns the last element. Errors on empty array.
Returns: Any — the removed last element
fn get(index: Number)Returns the element at the given index. Errors if the index is out of bounds.
Parameters:
index(Number) — zero-based position
Returns: Any — the element at index
fn slice(start: Number, end: Number) -> ArrayReturns a subarray from start (inclusive) to end (exclusive).
Parameters:
start(Number) — start index (inclusive, 0-based)end(Number) — end index (exclusive)
Returns: Array — the subarray
concat
Section titled “concat”fn concat(other: Array) -> ArrayReturns a new array with elements from both arrays.
Parameters:
other(Array) — array to append
Returns: Array — a new array with the elements of both
reverse
Section titled “reverse”fn reverse() -> ArrayReturns a new array with elements in reverse order.
Returns: Array — a new reversed array
contains
Section titled “contains”fn contains(value: any) -> BooleanReturns true if the array contains the given value.
Parameters:
value(Any) — the value to search for
Returns: Boolean — true if the value is present
fn map(func: Function) -> ArrayApplies a function to each element, returns a new array.
Parameters:
func(Function) — fn(element) -> new_element
Returns: Array — a new array of transformed elements
filter
Section titled “filter”fn filter(func: Function) -> ArrayReturns a new array with only elements satisfying the predicate.
Parameters:
func(Function) — fn(element) -> bool
Returns: Array — a new array of matching elements
reduce
Section titled “reduce”fn reduce(func: Function, initial: any)Reduces the array to a single value.
Parameters:
func(Function) — fn(accumulator, element) -> new_accumulatorinitial(Any) — starting accumulator value
Returns: Any — the final accumulated value
fn iter() -> IteratorReturns an iterator over the array elements.
Returns: Iterator — an iterator over the elements
concat
Section titled “concat”fn concat(array1: Array, array2: Array) -> ArrayConcatenates two arrays.
Parameters:
array1(Array) — first arrayarray2(Array) — second array
Returns: Array — a new array containing all elements from both arrays
filter
Section titled “filter”fn filter(array: Array, func: Function) -> ArraySelects elements from an array that satisfy a predicate.
Example:
filter([1, 2, 3, 4], fn(x) { x > 2; }) returns [3, 4]
Parameters:
array(Array) — the array to filterfunc(Function) — returns truthy/falsy for each element
Returns: Array — a new array of matching elements
fn fold(array: Array, initial: any, func: Function) -> anyReduces an array to a single value using an accumulator function.
Example:
fold([1, 2, 3], 0, fn(acc, x) { acc + x; }) returns 6
Parameters:
array(Array) — the array to reduceinitial(Any) — starting value for the accumulatorfunc(Function) — takes (accumulator, element), returns new accumulator
Returns: Any — the final accumulated value
length
Section titled “length”fn length(array: Array) -> NumberReturns the number of elements in an array.
Parameters:
array(Array) — the array to measure
Returns: Number — the element count
fn map(array: Array, func: Function) -> ArrayTransforms each element of an array using a function.
Example:
map([1, 2, 3], fn(x) { x * 2; }) returns [2, 4, 6]
Parameters:
array(Array) — the array to transformfunc(Function) — takes one element, returns the transformed value
Returns: Array — a new array of transformed elements
fn range(start_or_end: Number, end: Number = NUL) -> ArrayGenerates an array of sequential numbers.
range(3); // => #[0, 1, 2]range(2, 5); // => #[2, 3, 4]Parameters:
start_or_end(Number) — if called with one arg, this is the end (start=0); if called with two args, this is the startend(Number) — exclusive upper bound
Returns: Array — sequential numbers from start to end-1
fn slice(array: Array, start: Number, end: Number) -> ArrayExtracts a subarray from start index to end index.
Parameters:
array(Array) — the source arraystart(Number) — start index (inclusive, 0-based)end(Number) — end index (exclusive)
Returns: Array — the subarray
String
Section titled “String”The String type: text values.
A String is a Unicode-aware run of text written with "..." literals. Its methods query length and case, split and join, search, slice, and convert text — returning new strings rather than mutating in place.
String
Section titled “String”Text value with Unicode support. Construct with literal syntax "hello".
length
Section titled “length”fn length() -> NumberReturns the character count (Unicode-aware).
Returns: Number — the character count
uppercase
Section titled “uppercase”fn uppercase() -> StringReturns the string converted to uppercase.
Returns: String — the uppercased string
lowercase
Section titled “lowercase”fn lowercase() -> StringReturns the string converted to lowercase.
Returns: String — the lowercased string
substring
Section titled “substring”fn substring(start: Number, end: Number) -> StringReturns a substring from start to end (Unicode-aware).
Parameters:
start(Number) — start index (inclusive, 0-based)end(Number) — end index (exclusive)
Returns: String — the substring
fn split(delimiter: String) -> ArraySplits the string by a delimiter, returns an array of strings.
Parameters:
delimiter(String) — the string to split on
Returns: Array — the parts as Strings
contains
Section titled “contains”fn contains(needle: String) -> BooleanReturns true if the string contains the given substring.
Parameters:
needle(String) — the substring to search for
Returns: Boolean — true if needle is present
fn trim() -> StringReturns the string with leading and trailing whitespace removed.
Returns: String — the trimmed string
replace
Section titled “replace”fn replace(old: String, new: String) -> StringReturns the string with all occurrences of old replaced with new.
Parameters:
old(String) — the substring to findnew(String) — the replacement string
Returns: String — the string with replacements applied
starts_with
Section titled “starts_with”fn starts_with(prefix: String) -> BooleanReturns true if the string starts with the given prefix.
Parameters:
prefix(String) — the prefix to check
Returns: Boolean — true if the string starts with prefix
ends_with
Section titled “ends_with”fn ends_with(suffix: String) -> BooleanReturns true if the string ends with the given suffix.
Parameters:
suffix(String) — the suffix to check
Returns: Boolean — true if the string ends with suffix
repeat
Section titled “repeat”fn repeat(n: Number) -> StringReturns a new string by repeating this string n times.
Parameters:
n(Number) — number of repetitions
Returns: String — the repeated string
fn iter() -> IteratorReturns an iterator over the characters.
Returns: Iterator — an iterator over the characters
The Dict type: key–value maps.
A Dict maps String or Number keys to values of any type. Construct one with the #{"key": value} literal, then read, update, and iterate its entries. Keys are unique, so setting an existing key updates it in place.
Key-value mapping with String or Number keys. Construct with #{"key": value} literal syntax.
fn get(key: String or Number)Returns the value for the given key, or NUL if not found.
Parameters:
key(String | Number) — the key to look up
Returns: Any — the value for key, or NUL if absent
fn set(key: String or Number, value: any) -> DictSets a key-value pair in place.
Parameters:
key(String | Number) — the key to setvalue(Any) — the value to associate
Returns: Dict — the dict, for chaining
remove
Section titled “remove”fn remove(key: String or Number)Removes a key in place.
Parameters:
key(String | Number) — the key to remove
Returns: Any — the removed value, or NUL if the key was not found
fn keys() -> ArrayReturns an Array of all keys.
Returns: Array — all keys
values
Section titled “values”fn values() -> ArrayReturns an Array of all values.
Returns: Array — all values
length
Section titled “length”fn length() -> NumberReturns the number of entries.
Returns: Number — the entry count
contains_key
Section titled “contains_key”fn contains_key(key: String or Number) -> BooleanReturns true if the dict contains the given key.
Parameters:
key(String | Number) — the key to check
Returns: Boolean — true if key is present
entries
Section titled “entries”fn entries() -> ArrayReturns an Array of [key, value] pairs.
Returns: Array — one [key, value] pair per entry
fn merge(other: Dict) -> DictReturns a new dict with entries from both dicts merged. Does not mutate either dict.
Parameters:
other(Dict) — dict to merge in (its keys override on conflict)
Returns: Dict — a new merged dict
fn map(func: Function) -> DictTransforms values using a function.
Parameters:
func(Function) — fn(key, value) -> new_value
Returns: Dict — a new dict with transformed values
filter
Section titled “filter”fn filter(func: Function) -> DictFilters entries by predicate.
Parameters:
func(Function) — fn(key, value) -> bool
Returns: Dict — a new dict with matching entries
reduce
Section titled “reduce”fn reduce(func: Function, initial: any)Reduces entries to a single value.
Parameters:
func(Function) — fn(accumulator, key, value) -> new_accumulatorinitial(Any) — starting accumulator value
Returns: Any — the final accumulated value
fn iter() -> IteratorReturns an Iterator over the keys.
Returns: Iterator — an iterator over the keys
Iterator
Section titled “Iterator”The Iterator type: lazy sequences.
An Iterator is a lazy stream of values with chainable transformations (map, filter, take, and more) that compute only as elements are pulled. Obtain one with .iter() on an array, string, or pattern, and materialize the result with .collect().
Iterator
Section titled “Iterator”Lazy sequence of values with chainable transformations. Obtain from .iter() on arrays, strings, or patterns.
Advancing
Section titled “Advancing”fn next()Returns the next value, or nil if exhausted.
Returns: Any — the next value, or nil if exhausted
fn take(n: Number) -> IteratorReturns a lazy iterator yielding the first n elements.
Parameters:
n(Number) — maximum number of elements to yield
Returns: Iterator — a lazy iterator over the first n elements
fn skip(n: Number) -> IteratorReturns a lazy iterator that skips the first n elements.
Parameters:
n(Number) — number of elements to skip
Returns: Iterator — a lazy iterator past the first n elements
step_by
Section titled “step_by”fn step_by(step: Number) -> IteratorReturns a lazy iterator yielding every nth element.
Parameters:
step(Number) — take every nth element
Returns: Iterator — a lazy iterator over every step-th element
Transforming
Section titled “Transforming”enumerate
Section titled “enumerate”fn enumerate() -> IteratorReturns a lazy iterator yielding [index, value] pairs.
Returns: Iterator — a lazy iterator of [index, value] pairs
fn map(func: Function) -> ArrayApplies a function to each element, returns an array.
Parameters:
func(Function) — fn(element) -> new_element
Returns: Array — a new array of transformed elements
filter
Section titled “filter”fn filter(func: Function) -> ArrayFilters elements by predicate, returns an array.
Parameters:
func(Function) — fn(element) -> bool
Returns: Array — a new array of matching elements
fn zip(other: Iterator) -> IteratorZips this iterator with another, yielding [a, b] pairs.
Parameters:
other(Iterator) — iterator to zip with
Returns: Iterator — a lazy iterator of [a, b] pairs
fn chain(other: Iterator) -> IteratorChains another iterator after this one.
Parameters:
other(Iterator) — iterator to append
Returns: Iterator — a lazy iterator over both in sequence
flatten
Section titled “flatten”fn flatten() -> ArrayFlattens nested arrays into a single array.
Returns: Array — the flattened elements
Consuming
Section titled “Consuming”collect
Section titled “collect”fn collect() -> ArrayCollects all remaining elements into an array.
Returns: Array — the remaining elements
fn count() -> NumberCounts remaining elements (consumes the iterator).
Returns: Number — the count of remaining elements
fn first()Returns the first element, or nil if empty.
Returns: Any — the first element, or nil if empty
fn last()Returns the last element, or nil if empty. Warning: consumes the entire iterator; hangs on infinite iterators.
Returns: Any — the last element, or nil if empty
fn find(func: Function)Returns the first element matching the predicate, or nil.
Parameters:
func(Function) — fn(element) -> bool
Returns: Any — the first matching element, or nil
fn any(func: Function) -> BooleanReturns true if any element matches the predicate.
Parameters:
func(Function) — fn(element) -> bool
Returns: Boolean — true if at least one element matches
fn all(func: Function) -> BooleanReturns true if all elements match the predicate.
Parameters:
func(Function) — fn(element) -> bool
Returns: Boolean — true if every element matches
fn fold(initial: any, func: Function)Folds the iterator to a single value.
Parameters:
initial(Any) — starting accumulator valuefunc(Function) — fn(accumulator, element) -> new_accumulator
Returns: Any — the final accumulated value
Utilities
Section titled “Utilities”Global utility and introspection functions.
Cross-cutting helpers that don’t belong to a single type: high-resolution timing and sleeping, value inspection (type, show), loading files, and hot-reloading native extensions. All are in scope anywhere in a script.
fn clock() -> NumberReturns time in nanoseconds from an arbitrary reference point. Useful for benchmarking and timing operations.
Returns: Number — nanoseconds from an arbitrary reference point
load_file
Section titled “load_file”fn load_file(path: String) -> StringReads a text file and returns its contents as a String. The path is resolved relative to the directory of the .non file being run (falling back to the working directory). Useful for keeping GLSL shaders in external files: gfx.Visual(load_file("shaders/plasma.glsl")).
Parameters:
path(String) — file path, relative to the current .non file
Returns: String — the file contents (UTF-8)
fn print(value: any, newline: Boolean = true) -> NULWrites a value to the output, followed by a newline. Instances that define __str__ are formatted through it.
Parameters:
value(Any) — value to writenewline(Boolean) — append a trailing newline; pass false to suppress it
Returns: NUL — nothing
fn put(value: any) -> NULWrites a value to the output with no trailing newline. Shorthand for print(value, false); useful for building a line piecewise.
Parameters:
value(Any) — value to write
Returns: NUL — nothing
reload_ext
Section titled “reload_ext”fn reload_ext(name: String) -> NULReloads a native extension from disk. Fails if any objects from the extension still exist — drop them first.
Parameters:
name(String) — extension name to reload
Returns: NUL — nothing
fn show(value: any = NUL) -> NULDisplays detailed information about a value. For modules: name, path, exports, and documentation. For functions: the full typed signature, parameter types, and doc comments. For other values: the runtime type and representation.
Parameters:
value(Any) — any resonon value
Returns: NUL — nothing; prints the information
fn sleep(seconds: Number) -> NULPauses execution for the given number of seconds.
Useful for timed recording, waiting for hardware, or scripted workflows.
Parameters:
seconds(Number) — duration to sleep (e.g. 1.5 for 1500ms)
Returns: NUL — nothing
fn type(value: any = NUL) -> StringReturns the type name of a value as a string.
Parameters:
value(Any) — any resonon value
Returns: String — the value’s type name
Scalar math functions.
These mirror the math builtins available inside dsp blocks, so the same vocabulary works in scripts and DSP graphs. All operate on Number.
fn abs(x: Number) -> NumberAbsolute value.
Parameters:
x(Number) — the input value
Returns: Number — the absolute value
fn ceil(x: Number) -> NumberSmallest integer greater than or equal to the value.
Parameters:
x(Number) — the input value
Returns: Number — the ceiling
fn clamp(x: Number, lo: Number, hi: Number) -> NumberConstrains a value to the inclusive range [lo, hi].
Parameters:
x(Number) — the value to constrainlo(Number) — lower boundhi(Number) — upper bound
Returns: Number — the clamped value
fn cos(x: Number) -> NumberCosine of an angle in radians.
Parameters:
x(Number) — angle in radians
Returns: Number — the cosine
fn exp(x: Number) -> NumberExponential function (e raised to the power x).
Parameters:
x(Number) — the exponent
Returns: Number — e to the power x
fn floor(x: Number) -> NumberLargest integer less than or equal to the value.
Parameters:
x(Number) — the input value
Returns: Number — the floor
fn fract(x: Number) -> NumberFractional part of the value (the part after the decimal point).
Parameters:
x(Number) — the input value
Returns: Number — the fractional part
fn ftom(freq: Number) -> NumberConverts a frequency in Hz to a MIDI note number.
Parameters:
freq(Number) — frequency in Hz
Returns: Number — MIDI note number (may be fractional)
fn lerp(a: Number, b: Number, t: Number) -> NumberLinearly interpolates between two values.
Parameters:
a(Number) — start value (t = 0)b(Number) — end value (t = 1)t(Number) — interpolation factor
Returns: Number — the interpolated value
fn log(x: Number) -> NumberNatural logarithm (base e).
Parameters:
x(Number) — the input value
Returns: Number — the natural logarithm
fn log10(x: Number) -> NumberBase-10 logarithm.
Parameters:
x(Number) — the input value
Returns: Number — the base-10 logarithm
fn log2(x: Number) -> NumberBase-2 logarithm.
Parameters:
x(Number) — the input value
Returns: Number — the base-2 logarithm
fn max(a: Number, b: Number) -> NumberLarger of two numbers.
Parameters:
a(Number) — first valueb(Number) — second value
Returns: Number — the larger value
fn min(a: Number, b: Number) -> NumberSmaller of two numbers.
Parameters:
a(Number) — first valueb(Number) — second value
Returns: Number — the smaller value
fn mtof(note: Number) -> NumberConverts a MIDI note number to frequency in Hz.
Parameters:
note(Number) — MIDI note number (69 = A4 = 440 Hz)
Returns: Number — frequency in Hz
fn pow(base: Number, exponent: Number) -> NumberRaises a base to a power.
Parameters:
base(Number) — the baseexponent(Number) — the exponent
Returns: Number — base raised to the exponent
fn round(value: Number, places: Number = 0) -> NumberRounds a number to the given number of decimal places.
Parameters:
value(Number) — the number to roundplaces(Number) — decimal places
Returns: Number — the rounded number
fn sin(x: Number) -> NumberSine of an angle in radians.
Parameters:
x(Number) — angle in radians
Returns: Number — the sine
fn sqrt(x: Number) -> NumberSquare root.
Parameters:
x(Number) — the input value
Returns: Number — the square root
fn tan(x: Number) -> NumberTangent of an angle in radians.
Parameters:
x(Number) — angle in radians
Returns: Number — the tangent
fn tanh(x: Number) -> NumberHyperbolic tangent.
Parameters:
x(Number) — the input value
Returns: Number — the hyperbolic tangent