ReferenceControlArcReferenceBuilt Ins

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)
ParameterTypeDescription
inputseries or strValue to measure
Returnsi64Number of elements or bytes

now

Returns the current timestamp in nanoseconds.

current := now()         // i64 ns
ParameterTypeDescription
Returnsi64Current timestamp (nanoseconds)

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{}
ConfigTypeDescription
periodTimeSpanTime between firings
Outputu81 when firing, 0 otherwise

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
ConfigTypeDescription
durationTimeSpanTime to wait
Outputu81 when duration elapsed, 0 otherwise
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
ConfigTypeDescription
durationTimeSpanReset after this duration (optional)
counti64Reset after this many samples (optional)
InputnumericValue to average
Outputf64Running average

min

Computes a running minimum with optional reset.

sensor -> min{duration=1min} -> min_display
sensor -> min{count=50} -> min_display
ConfigTypeDescription
durationTimeSpanReset after this duration (optional)
counti64Reset after this many samples (optional)
InputnumericValue to track
Outputsame as inputRunning minimum

max

Computes a running maximum with optional reset.

sensor -> max{duration=1min} -> max_display
sensor -> max{count=50} -> max_display
ConfigTypeDescription
durationTimeSpanReset after this duration (optional)
counti64Reset after this many samples (optional)
InputnumericValue to track
Outputsame as inputRunning maximum

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
ConfigTypeDescription
InputnumericValue to differentiate
Outputf64Rate of change per second (dx/dt)

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{}
ConfigTypeDescription
channelchannel referenceChannel to read from
Outputchannel element typeLatest channel value

write

Writes to a Synnax channel (sink node).

processor{} -> write{channel=ox_pt_cmd}
ConfigTypeDescription
channelchannel referenceChannel to write to
Inputchannel element typeValue to write

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{}
}
InputTypeDescription
conditionu8Routing condition
Outputs
trueanyValue when condition is truthy
falseanyValue when condition is falsy

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
ConfigTypeDescription
durationTimeSpanRequired stability period
InputanySignal to debounce
Outputsame as inputStable value (or nothing if unstable)

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"
}
ConfigTypeDescription
statusKeystrName of status to update
variantstrSeverity: "success", "warning", or "error"
messagestrNotification message
Inputu8Trigger condition

Workflow:

  1. Create a status in Synnax Console
  2. Reference that status in Arc using statusKey
  3. 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}
ConfigTypeRequiredDescription
valueu8YesAuthority level (0-255)
channelchannel referenceNoSpecific channel to change (default: all channels)

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
ConfigTypeDescription
valueanyValue to output
Outputsame as valueThe constant value

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
}

Summary Table

FunctionCategoryDescription
lenCoreLength of series or string
nowCoreCurrent timestamp (ns)
intervalTimingPeriodic trigger
waitTimingOne-shot delay
avgStatisticsRunning average
minStatisticsRunning minimum
maxStatisticsRunning maximum
derivativeStatisticsRate of change (dx/dt)
onI/ORead from channel
writeI/OWrite to channel
selectSignalRoute by condition
stable_forSignalDebounce filter
set_statusStatusUpdate Console status
set_authorityAuthorityChange control authority
constantUtilityStatic value output