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.
(+ 3 4) ; 7
(+ [1 2 3] 10) ; [11 12 13]
(+ [1 2 3] [10 20 30]) ; [11 22 33]
(+ [1 2 3] 10) ; [11 12 13]
(+ [1 2 3] [10 20 30]) ; [11 22 33]
(- a b)
atomic
Subtraction.
(- 10 3) ; 7
(- [10 20 30] 5) ; [5 15 25]
(- [10 20 30] 5) ; [5 15 25]
(* a b)
atomic
Multiplication.
(* 3 4) ; 12
(* [2 3 4] [10 10 10]) ; [20 30 40]
(* [2 3 4] [10 10 10]) ; [20 30 40]
(/ a b)
atomic
Division. Integer division for integer arguments, float division otherwise.
(/ 10 3) ; 3
(/ 10.0 3) ; 3.333...
(/ 10.0 3) ; 3.333...
(% a b)
atomic
Modulo (remainder).
(% 10 3) ; 1
(% [10 11 12] 3) ; [1 2 0]
(% [10 11 12] 3) ; [1 2 0]
(neg x)
atomic
Negate a number.
(neg 5) ; -5
(neg [1 -2 3]) ; [-1 2 -3]
(neg [1 -2 3]) ; [-1 2 -3]
(abs x)
atomic
Absolute value.
(abs -7) ; 7
(abs [-3 0 5]) ; [3 0 5]
(abs [-3 0 5]) ; [3 0 5]
(sqrt x)
atomic
Square root. Returns float.
(sqrt 16) ; 4.0
(sqrt [4 9 25]) ; [2.0 3.0 5.0]
(sqrt [4 9 25]) ; [2.0 3.0 5.0]
(round x)
atomic
Round to nearest integer.
(round 3.7) ; 4
(round [1.2 2.5 3.8]) ; [1 3 4]
(round [1.2 2.5 3.8]) ; [1 3 4]
(floor x)
atomic
Round down to nearest integer.
(floor 3.9) ; 3
(ceil x)
atomic
Round up to nearest integer.
(ceil 3.1) ; 4
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.
(== 3 3) ; 1b
(== [1 2 3] 2) ; [0b 1b 0b]
(== [1 2 3] 2) ; [0b 1b 0b]
(!= a b)
atomic
Not equal.
(!= 3 4) ; 1b
(< a b)
atomic
Less than.
(< 3 5) ; 1b
(< [1 5 3] 4) ; [1b 0b 1b]
(< [1 5 3] 4) ; [1b 0b 1b]
(<= a b)
atomic
Less than or equal.
(<= 3 3) ; 1b
(> a b)
atomic
Greater than.
(> 5 3) ; 1b
(>= a b)
atomic
Greater than or equal.
(>= 5 5) ; 1b
(within x lo hi)
atomic
Check if value is within a range (inclusive).
(within 5 3 7) ; 1b
(within [1 5 9] 3 7) ; [0b 1b 0b]
(within [1 5 9] 3 7) ; [0b 1b 0b]
Logic
(and a b)
atomic
Logical AND. Works on booleans and boolean vectors.
(and (> x 0) (< x 10))
(or a b)
atomic
Logical OR.
(or (== x 0) (== x 10))
(not x)
atomic
Logical NOT. Flips boolean values.
(not 1b) ; 0b
(not [1b 0b 1b]) ; [0b 1b 0b]
(not [1b 0b 1b]) ; [0b 1b 0b]
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.
(sum [1 2 3 4]) ; 10
(count x)
aggregate
Number of elements. Counts non-null values.
(count [1 2 3]) ; 3
(avg x)
aggregate
Arithmetic mean.
(avg [2 4 6]) ; 4.0
(min x)
aggregate
Minimum value.
(min [5 1 9]) ; 1
(max x)
aggregate
Maximum value.
(max [5 1 9]) ; 9
(med x)
aggregate
Median value.
(med [1 3 5 7 9]) ; 5
(dev x)
aggregate
Standard deviation.
(dev [2 4 4 4 5 5 7 9]) ; 2.0
(first x)
aggregate
First element of a vector.
(first [10 20 30]) ; 10
(last x)
aggregate
Last element of a vector.
(last [10 20 30]) ; 30
(distinct x)
aggregate
Unique elements of a vector.
(distinct [1 2 2 3 1]) ; [1 2 3]
Ordering
Sorting and ranking operations for vectors and tables.
(asc x)
Sort a vector in ascending order.
(asc [3 1 2]) ; [1 2 3]
(desc x)
Sort a vector in descending order.
(desc [3 1 2]) ; [3 2 1]
(iasc x)
Return indices that would sort the vector ascending (grade up).
(iasc [30 10 20]) ; [1 2 0]
(idesc x)
Return indices that would sort the vector descending (grade down).
(idesc [30 10 20]) ; [0 2 1]
(xasc col table)
Sort a table ascending by the named column.
(xasc 'price trades)
(xdesc col table)
Sort a table descending by the named column.
(xdesc 'price trades)
(xrank n x)
Assign each element to one of
n equal-sized buckets (quantile rank).(xrank 4 [10 20 30 40 50 60 70 80]) ; [0 0 1 1 2 2 3 3]
Generation
Functions for creating, reshaping, and searching vectors.
(til n)
Generate integers from 0 to n-1.
(til 5) ; [0 1 2 3 4]
(take n x)
Take the first
n elements from a vector, or repeat/cycle x to length n.(take 3 [10 20 30 40]) ; [10 20 30]
(take [A B] 5) ; [A B A B A]
(take [A B] 5) ; [A B A B A]
(drop n x)
Drop the first
n elements from a vector.(drop 2 [10 20 30 40]) ; [30 40]
(reverse x)
Reverse a vector.
(reverse [1 2 3]) ; [3 2 1]
(where x)
Return indices where the boolean vector is true.
(where [0b 1b 0b 1b]) ; [1 3]
(where (> [10 5 20] 8)) ; [0 2]
(where (> [10 5 20] 8)) ; [0 2]
(find x val)
Find the index of the first occurrence of
val in vector x.(find [10 20 30] 20) ; 1
(xbar n x)
Round each element down to the nearest multiple of
n (bucketing).(xbar 5 [3 7 12 18]) ; [0 5 10 15]
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.(map (fn [x] (* x x)) [1 2 3]) ; [1 4 9]
(fold f init x)
Left fold. Accumulate over
x starting from init using binary function f.(fold + 0 [1 2 3 4]) ; 10
(scan f x)
Running fold (prefix scan). Returns a vector of intermediate accumulation results.
(scan + [1 2 3 4]) ; [1 3 6 10]
(scan * [1 2 3 4]) ; [1 2 6 24]
(scan * [1 2 3 4]) ; [1 2 6 24]
(apply f args)
Apply function
f with a list of arguments.(apply + [1 2]) ; 3
(filter f x)
Keep elements of
x where f returns true.(filter (fn [x] (> x 2)) [1 2 3 4]) ; [3 4]
(pmap f x)
Parallel map. Like
map but distributes work across threads for large inputs.(pmap (fn [x] (* x x)) (til 1000000))
Quick Reference Table
| Category | Functions |
|---|---|
| Arithmetic | + - * / % neg abs sqrt 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 drop 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.