Built-In Functions
Arc built-in function reference for timing, statistics, I/O, signal processing, and utility functions
Arc’s standard library is focused on core timing, statistics, and I/O operations.
Functions like sqrt, abs, and trigonometric functions are planned for future
releases.
Core Functions
len
Returns the length of a series or string.
data := [1.0, 2.0, 3.0]
length := len(data) // 3 (i64)
msg := "hello"
chars := len(msg) // 5 (i64) now
Returns the current timestamp in nanoseconds.
current := now() // i64 ns Timing Nodes
Timing nodes create periodic and delayed behaviors in the reactive scope.
interval
Fires repeatedly at a specified period.
interval{period=50ms} -> controller{}
interval{period=1s} -> logger{} The first tick fires immediately at t=0. Subsequent ticks fire when
elapsed - lastFired >= period. When a stage is re-entered, all intervals in that stage
reset and fire immediately on the next tick of the interval.
// 20Hz control loop
interval{period=50ms} -> pressure_controller{}
// 1Hz data logging
interval{period=1s} -> log_all_sensors{} // The interval resets each time the program transitions back to 'on'.
// It fires immediately on re-entry, then every 1s after that.
sequence main {
stage on {
1 -> heater_cmd,
interval{period=1s} -> temp > 200 => off,
}
stage off {
0 -> heater_cmd,
start_cmd => on,
}
} wait
Fires once after a specified duration. Resets when the stage is re-entered.
wait{duration=5s} => next sequence test {
stage hold {
// Wait 30 seconds before proceeding
wait{duration=30s} => next
}
stage proceed {
// continue
}
} wait resets when re-entering a stage, allowing it to be used in loops.
Statistical Functions
Statistical functions operate on streaming data with optional reset conditions.
avg
Computes a running average with optional reset.
sensor -> avg{duration=10s} -> avg_display
sensor -> avg{count=100} -> avg_display min
Computes a running minimum with optional reset.
sensor -> min{duration=1min} -> min_display
sensor -> min{count=50} -> min_display max
Computes a running maximum with optional reset.
sensor -> max{duration=1min} -> max_display
sensor -> max{count=50} -> max_display All statistical functions support a reset input signal (u8) for manual reset.
derivative
Computes the rate of change per second (dx/dt) of a streaming signal.
sensor -> derivative{} -> rate_display The derivative node tracks the previous value and timestamp across invocations. On each
sample, it computes (current - previous) / dt, where dt is the elapsed time in
seconds. The first sample always outputs 0 since there is no previous value. If the
time delta is zero or negative, the output is also 0.
// Monitor rate of temperature change
thermocouple -> derivative{} -> temp_rate
// Chain with other nodes
pressure -> derivative{} -> rate > 100.0 => alarm I/O Nodes
on
Reads from a Synnax channel (source node).
on{channel=ox_pt_1} -> processor{} write
Writes to a Synnax channel (sink node).
processor{} -> write{channel=ox_pt_cmd} In most cases, you can reference channels directly by name without using on or
write explicitly.
Signal Processing Nodes
select
Routes a signal based on a boolean condition.
condition -> select{} -> {
true: handler_a{},
false: handler_b{}
} stable_for
Outputs only when the input value has been stable for a specified duration. Useful for debouncing noisy signals.
noisy_sensor -> stable_for{duration=100ms} -> stable_output Status Node
set_status
Updates a status that triggers notifications in Console.
ox_pt_1 > 500 -> set_status{
statusKey="overpressure",
variant="error",
message="Pressure exceeded limit"
} Workflow:
- Create a status in Synnax Console
- Reference that status in Arc using
statusKey - When the input is truthy, Arc updates the status and sends a notification
Authority
set_authority
Dynamically changes control authority during execution. Use this to escalate priority, release control, or adjust authority for specific channels at runtime.
All channels:
set_authority{value=200} Specific channel:
set_authority{value=255, channel=press_vlv_cmd} Set to minimum authority:
set_authority{value=0} Authority changes are flushed before channel writes in the same execution cycle. This means you can set authority and write to a channel in the same stage, and the authority change takes effect first.
Setting set_authority{(value = 0)} sets authority to the minimum, allowing any other
writer with authority above 0 to take control. Empty stages do NOT lower authority —
the writer holds its current authority as long as the program is running.
Usage in a stage:
stage emergency {
set_authority{value=255},
0 -> press_vlv_cmd,
1 -> vent_vlv_cmd
} Utility Nodes
constant
Outputs a static value.
constant{value=100.0} -> setpoint Math Operations
Arc provides the ^ operator for exponentiation:
result := 2 ^ 8 // 256
square := value ^ 2 // value squared Arc does not currently include abs, sqrt, or trigonometric functions. Use
conditional logic for absolute value:
// Absolute value workaround
if x < 0 {
x = 0.0 - x
}