Math, Comparison, Aggregation & Iteration¶
All numeric, logical, aggregation, ordering, generation, and higher-order operations available in Rayfall. Operations marked FN_ATOMIC auto-map over vectors element-wise.
Arithmetic¶
All arithmetic operations are atomic — they work on scalars and auto-map element-wise over vectors.
(+ a b) — atomic¶
Addition. Works on integers, floats, dates, and times.
(- a b) — atomic¶
Subtraction.
(* a b) — atomic¶
Multiplication.
(/ a b) — atomic¶
Division. Integer division for integer arguments, float division otherwise.
(% a b) — atomic¶
Modulo (remainder).
(neg x) — atomic¶
Negate a number.
(round x) — atomic¶
Round to nearest integer.
(floor x) — atomic¶
Round down to nearest integer.
(ceil x) — atomic¶
Round up to nearest integer.
Comparison¶
All comparison operations are atomic and return boolean values (or boolean vectors).
(== a b) — atomic¶
Equal. Works on all types including strings and symbols.
(!= a b) — atomic¶
Not equal.
(< a b) — atomic¶
Less than.
(<= a b) — atomic¶
Less than or equal.
(> a b) — atomic¶
Greater than.
(>= a b) — atomic¶
Greater than or equal.
(within vec [lo hi])¶
Check if each element of a vector is within a range (inclusive). The second argument is a 2-element vector [lo hi].
Logic¶
(and a b) — atomic¶
Logical AND. Works on booleans and boolean vectors.
(or a b) — atomic¶
Logical OR.
(not x) — atomic¶
Logical NOT. Flips boolean values.
Aggregation¶
Aggregation functions reduce a vector to a single scalar. They carry the FN_AGGR flag and are recognized by the select/update query planner for group-by operations.
(sum x) — aggregate¶
Sum of all elements.
(count x) — aggregate¶
Number of elements. Counts non-null values.
(avg x) — aggregate¶
Arithmetic mean.
(min x) — aggregate¶
Minimum value.
(max x) — aggregate¶
Maximum value.
(med x) — aggregate¶
Median value.
(dev x) — aggregate¶
Standard deviation.
(first x) — aggregate¶
First element of a vector.
(last x) — aggregate¶
Last element of a vector.
(distinct x) — aggregate¶
Unique elements of a vector.
Ordering¶
Sorting and ranking operations for vectors and tables.
(asc x)¶
Sort a vector in ascending order.
(desc x)¶
Sort a vector in descending order.
(iasc x)¶
Return indices that would sort the vector ascending (grade up).
(idesc x)¶
Return indices that would sort the vector descending (grade down).
(xasc col table)¶
Sort a table ascending by the named column.
(xdesc col table)¶
Sort a table descending by the named column.
(xrank n x)¶
Assign each element to one of n equal-sized buckets (quantile rank).
Generation¶
Functions for creating, reshaping, and searching vectors.
(til n)¶
Generate integers from 0 to n-1.
(take x n)¶
Take the first n elements from a vector, or repeat/cycle x to length n.
(reverse x)¶
Reverse a vector.
(where x)¶
Return indices where the boolean vector is true.
(find x val)¶
Find the index of the first occurrence of val in vector x.
(xbar x n)¶
Round each element down to the nearest multiple of n (bucketing).
Higher-order Functions¶
Functions that take other functions as arguments for flexible iteration patterns.
(map f x)¶
Apply function f to each element of x. Returns a list of results.
(fold f init x)¶
Left fold. Accumulate over x starting from init using binary function f.
(scan f x)¶
Running fold (prefix scan). Returns a vector of intermediate accumulation results.
(apply f ...args)¶
Apply function f to the given arguments.
(filter vec mask)¶
Keep elements of vec where the boolean mask is true.
(pmap f x)¶
Parallel map. Like map but distributes work across threads for large inputs.
Quick Reference Table¶
| Category | Functions |
|---|---|
| Arithmetic | + - * / % neg round floor ceil |
| Comparison | == != < <= > >= within |
| Logic | and or not |
| Aggregation | sum count avg min max med dev first last distinct |
| Ordering | asc desc iasc idesc xasc xdesc xrank |
| Generation | til take reverse where find xbar |
| Higher-order | map fold scan apply filter pmap |
Auto-mapping
All operations tagged FN_ATOMIC (arithmetic, comparison, logic) automatically map over vectors element-wise. You do not need explicit map calls for these — (+ [1 2 3] 10) works directly.