Functions Reference
Complete reference for all Rayfall built-in functions. Each entry shows the function name, arity type (unary/binary/variadic), flags, description, and example usage.
Legend: Functions marked atomic auto-map element-wise over vectors. Functions marked aggr reduce vectors to scalars. Functions marked special receive unevaluated arguments.
Arithmetic
All arithmetic operators are atomic — they auto-map over vectors and broadcast scalars.
| Function | Type | Description | Example |
+ | binary | Addition | (+ 3 4) → 7 |
- | binary | Subtraction | (- 10 3) → 7 |
* | binary | Multiplication | (* 3 4) → 12 |
/ | binary | Division (float result) | (/ 7 2) → 3.5 |
% | binary | Modulo | (% 7 3) → 1 |
div | binary | Integer division (floor) | (div 7 2) → 3 |
neg | unary | Negate | (neg 5) → -5 |
round | unary | Round to nearest integer | (round 3.7) → 4.0 |
floor | unary | Floor (round down) | (floor 3.7) → 3.0 |
ceil | unary | Ceiling (round up) | (ceil 3.2) → 4.0 |
xbar | binary | Round down to nearest multiple (bucketing) | (xbar 5 [3 7 12]) → [0 5 10] |
Vector examples:
(+ [1 2 3] [10 20 30])
(* [1 2 3] 10)
(neg [1 -2 3])
(xbar 10 [3 15 27])
Comparison
All comparison operators are atomic and return boolean results.
| Function | Type | Description | Example |
> | binary | Greater than | (> 5 3) → true |
< | binary | Less than | (< 3 5) → true |
>= | binary | Greater than or equal | (>= 5 5) → true |
<= | binary | Less than or equal | (<= 3 5) → true |
== | binary | Equal | (== 3 3) → true |
!= | binary | Not equal | (!= 3 4) → true |
within | binary | Check if value falls within a range | (within 5 [3 7]) → true |
Logic
| Function | Type | Description | Example |
and | binary | Logical AND | (and true false) → false |
or | binary | Logical OR | (or true false) → true |
not | unary | Logical NOT | (not true) → false |
Aggregation
Aggregation functions are marked aggr and reduce vectors to scalar values. Used in select with by: for group-by aggregation.
| Function | Type | Description | Example |
sum | unary, aggr | Sum of all elements | (sum [1 2 3]) → 6 |
count | unary, aggr | Count of elements | (count [1 2 3]) → 3 |
avg | unary, aggr | Arithmetic mean | (avg [1 2 3]) → 2.0 |
min | unary, aggr | Minimum value | (min [3 1 2]) → 1 |
max | unary, aggr | Maximum value | (max [3 1 2]) → 3 |
med | unary, aggr | Median value | (med [1 3 2]) → 2 |
dev | unary, aggr | Standard deviation | (dev [1 2 3]) → 0.816... |
first | unary | First element of vector | (first [10 20 30]) → 10 |
last | unary | Last element of vector | (last [10 20 30]) → 30 |
(select {from: trades
by: {sym: sym}
cols: {hi: (max price) lo: (min price) n: (count price)}})
Higher-Order Functions
Functions that take other functions as arguments.
| Function | Type | Description | Example |
map | variadic | Apply function to each element | (map (fn [x] (* x 2)) [1 2 3]) → [2 4 6] |
pmap | variadic | Parallel map (multi-threaded) | (pmap (fn [x] (* x x)) [1 2 3]) → [1 4 9] |
filter | binary | Keep elements matching predicate | (filter (fn [x] (> x 2)) [1 2 3 4]) → [3 4] |
fold | variadic | Reduce with function and initial value | (fold + 0 [1 2 3]) → 6 |
fold-left | variadic | Left-associative fold | (fold-left - 10 [1 2 3]) → 4 |
fold-right | variadic | Right-associative fold | (fold-right - 10 [1 2 3]) → -8 |
scan | variadic | Running fold (returns all intermediate results) | (scan + 0 [1 2 3]) → [1 3 6] |
scan-left | variadic | Left-to-right running fold | (scan-left + 0 [1 2 3]) → [1 3 6] |
scan-right | variadic | Right-to-left running fold | (scan-right + 0 [1 2 3]) → [6 5 3] |
apply | variadic | Apply function with list of arguments | (apply + [1 2 3]) → 6 |
map-left | variadic | Map with left argument fixed | (map-left + 10 [1 2 3]) → [11 12 13] |
map-right | variadic | Map with right argument fixed | (map-right - [10 20 30] 5) → [5 15 25] |
Collection Operations
Operations on vectors as collections.
| Function | Type | Description | Example |
distinct | unary | Remove duplicates | (distinct [1 2 2 3]) → [1 2 3] |
in | binary | Membership test (element in vector) | (in 2 [1 2 3]) → true |
except | binary | Set difference | (except [1 2 3] [2]) → [1 3] |
union | binary | Set union | (union [1 2] [2 3]) → [1 2 3] |
sect | binary | Set intersection | (sect [1 2 3] [2 3 4]) → [2 3] |
take | binary | Take first/last N elements | (take 2 [10 20 30]) → [10 20] |
at | binary | Index into vector | (at [10 20 30] 1) → 20 |
find | binary | Find index of value | (find [10 20 30] 20) → 1 |
reverse | unary | Reverse order | (reverse [1 2 3]) → [3 2 1] |
til | unary | Range [0..n) | (til 5) → [0 1 2 3 4] |
enlist | variadic | Wrap value(s) in a list | (enlist 1 2 3) → (1 2 3) |
concat | binary | Concatenate two vectors | (concat [1 2] [3 4]) → [1 2 3 4] |
raze | unary | Flatten a list of vectors into one | (raze (list [1 2] [3 4])) → [1 2 3 4] |
where | unary | Indices where boolean vector is true | (where [true false true]) → [0 2] |
group | unary | Group indices by value | (group [A B A]) → dict of groups |
diverse | unary | Check if all elements are unique | (diverse [1 2 3]) → true |
rand | binary | N random values from range or vector | (rand 3 100) → 3 random ints 0..99 |
bin | binary | Binary search (left boundary) | (bin [10 20 30] 25) → 1 |
binr | binary | Binary search (right boundary) | (binr [10 20 30] 25) → 2 |
unify | binary | Merge two tables/dicts, second takes precedence | (unify d1 d2) |
Sorting & Ordering
| Function | Type | Description | Example |
asc | unary | Sort ascending | (asc [3 1 2]) → [1 2 3] |
desc | unary | Sort descending | (desc [3 1 2]) → [3 2 1] |
iasc | unary | Indices that would sort ascending | (iasc [30 10 20]) → [1 2 0] |
idesc | unary | Indices that would sort descending | (idesc [30 10 20]) → [0 2 1] |
rank | unary | Rank of each element | (rank [30 10 20]) → [2 0 1] |
xasc | binary | Sort table ascending by column(s) | (xasc 'price trades) |
xdesc | binary | Sort table descending by column(s) | (xdesc 'price trades) |
xrank | binary | Assign rank buckets (quantiles) | (xrank 4 [10 20 30 40]) → [0 1 2 3] |
Table Operations
| Function | Type | Description | Example |
list | variadic | Create a list from vectors | (list [1 2] [A B]) |
table | binary | Create table from column names + list of vectors | (table [x y] (list [1 2] [A B])) |
key | unary | Get column names (table) or keys (dict) | (key trades) → [sym price size] |
value | unary | Get column data (table) or values (dict) | (value trades) |
dict | binary | Create dictionary from keys and values | (dict [a b] [1 2]) |
get | binary | Lookup key in dict/table | (get d 'a) → 1 |
remove | binary | Remove key from dict | (remove d 'a) |
row | binary | Extract single row from table as dict | (row trades 0) |
meta | unary | Get metadata (column types, lengths) | (meta trades) |
alter | variadic, special | In-place mutation of table column | (alter trades 'price (* price 1.1)) |
del | variadic, special | Delete columns or rows from table | (del trades 'temp_col) |
modify | variadic | Functional table update (returns new table) | (modify trades 'price (fn [p] (* p 1.1))) |
Query Operations
These are special forms that bridge to the Rayforce DAG executor.
| Function | Type | Description |
select | variadic, special | Query table with optional filter, projection, grouping, and aggregation |
update | variadic, special | Add or modify columns in a table |
insert | variadic, special | Insert rows into a table |
upsert | variadic, special | Insert or update rows (by key) |
(select {from: trades
where: (> price 100)
cols: {sym: sym notional: (* price size)}})
(select {from: trades
by: {sym: sym}
cols: {vwap: (/ (sum (* price size)) (sum size))
count: (count price)}})
(update {from: trades
cols: {notional: (* price size)}})
Joins
Rayforce supports four join types, all with time-series-aware semantics.
| Function | Type | Description |
left-join | variadic | Left join on matching columns. Unmatched rows filled with nulls. |
inner-join | variadic | Inner join — only matching rows. |
window-join | variadic, special | Join with time window constraint. Match rows within a time range. |
asof-join | variadic | As-of join — match the most recent preceding value. |
(left-join trades quotes 'sym)
(inner-join orders products 'product_id)
(window-join {left: trades right: quotes
on: [sym] window: [-1000 0]
cols: {avg_bid: (avg bid)}})
(asof-join trades quotes 'sym)
Pivot & Window
| Function | Type | Description | Example |
pivot | variadic | Pivot table — reshape long to wide format | (pivot trades 'sym 'date 'price) |
xbar | binary, atomic | Bucket values (time bucketing for OHLC bars) | (xbar 5 [3 7 12]) → [0 5 10] |
xrank | binary | Assign N rank buckets (quantile ranking) | (xrank 4 [10 20 30 40]) |
(select {from: trades
by: {sym: sym bucket: (xbar 300000 time)}
cols: {open: (first price)
high: (max price)
low: (min price)
close: (last price)
vol: (sum size)}})
String Operations
| Function | Type | Description | Example |
split | binary | Split string by delimiter | (split "a,b,c" ",") → ["a" "b" "c"] |
like | binary | Pattern match (glob-style with * and ?) | (like "hello" "hel*") → true |
concat | binary | Concatenate two strings or vectors | (concat "hello" " world") → "hello world" |
format | variadic | Format values as string | (format "x=%d" 42) |
Note: The executor supports additional string opcodes (STRLEN, UPPER, LOWER, TRIM, SUBSTR, REPLACE, CONCAT) at the DAG level. All string transformations propagate nulls: null input rows produce null output rows.
Date & Time
| Function | Type | Description | Example |
date | unary | Current date or extract date from timestamp | (date 0) → today's date |
time | unary | Current time or extract time from timestamp | (time 0) → current time |
timestamp | unary | Current timestamp (nanosecond precision) | (timestamp 0) |
Cross-temporal comparisons are supported: dates, times, and timestamps are all converted to nanoseconds internally for comparison operations.
Type Operations
| Function | Type | Description | Example |
type | unary | Get type name of a value | (type 42) → "i64" |
as | binary | Cast value to another type | (as "42" 'i64) → 42 |
nil? | unary | Test if value is null | (nil? x) |
rc | unary | Reference count of an object | (rc x) → 1 |
guid | unary | Generate N GUIDs (0 for one) | (guid 0) |
I/O & File Operations
| Function | Type | Description | Example |
println | variadic | Print values with newline | (println "hello" 42) |
print | unary | Print value without newline | (print "hello") |
show | variadic | Pretty-print a value (tables formatted) | (show trades) |
format | variadic | Format value to string | (format "val=%d" 42) |
read-csv | variadic | Load CSV file into table | (read-csv "data.csv") |
write-csv | variadic | Write table to CSV file | (write-csv trades "out.csv") |
read | unary | Read file contents as string | (read "file.txt") |
write | binary | Write string to file | (write "file.txt" "content") |
load | unary | Load and evaluate a Rayfall script | (load "lib.rfl") |
Control Flow
| Function | Type | Description | Example |
set | binary, special | Bind value to global variable | (set x 42) |
let | binary, special | Bind value to local variable | (let y (+ x 1)) |
if | variadic, special | Conditional (if/then/else) | (if (> x 0) "pos" "neg") |
do | variadic, special | Sequential execution, returns last | (do (set x 1) (set y 2) (+ x y)) |
fn | variadic, special | Create lambda function | (fn [x] (* x x)) |
try | binary, special | Error handling (expr handler) | (try (/ 1 0) (fn [e] 0)) |
raise | unary | Throw an error | (raise "bad input") |
return | unary | Early return from function | (return 42) |
quote | variadic, special | Return argument unevaluated | (quote (+ 1 2)) → (+ 1 2) |
resolve | variadic, special | Resolve a symbol in current scope | (resolve 'x) |
System & Utility
| Function | Type | Description | Example |
eval | unary | Evaluate a parsed expression | (eval (parse "(+ 1 2)")) → 3 |
parse | unary | Parse string into Rayfall expression | (parse "(+ 1 2)") |
gc | unary | Trigger garbage collection | (gc 0) |
system | unary | Execute shell command | (system "ls -la") |
getenv | unary | Get environment variable | (getenv "HOME") |
setenv | binary | Set environment variable | (setenv "KEY" "value") |
os-get-var | unary | Alias for getenv | (os-get-var "PATH") |
os-set-var | binary | Alias for setenv | (os-set-var "KEY" "val") |
exit | unary | Exit with status code | (exit 0) |
timeit | variadic, special | Benchmark an expression | (timeit (sum (til 1000000))) |
timer | unary | High-resolution monotonic nanosecond clock | (timer 0) |
args | unary | Command-line arguments | (args 0) |
env | unary | List all global environment bindings | (env 0) |
internals | unary | Show internal representation of object | (internals [1 2 3]) |
memstat | unary | Memory allocator statistics | (memstat 0) |
sysinfo | unary | System information (OS, CPU, memory) | (sysinfo 0) |
Serialization
| Function | Type | Description | Example |
ser | unary | Serialize value to binary format | (ser [1 2 3]) |
de | unary | Deserialize from binary format | (de bytes) |