processor
Builtin index · Signal processing
result = processor(f, [block=256], [state=], [rate=])
Input: f, block, state, rate · Output: result
What it is
f: a function (a value or the name of a user function) called once per block; block: block length in samples, positional or named, default 256; state: the initial state — passing it is what makes the processor stateful; rate: the design sample rate, a number or a frequency (48 kHz).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = processor(f, [block=256], [state=], [rate=]) | f —f: a function (a value or the name of a user function) called once per block.block optional (default 256)block: block length in samples, positional or named, default 256.state optionalstate: the initial state — passing it is what makes the processor stateful.rate number, optionalrate: the design sample rate, a number or a frequency (48 kHz). | Model —kind "processor"latency —samples | Returns a Model (kind "processor") with fields fn, block, latency (samples), stateful, plus state when stateful and rate/latency_ms when a rate was given. Run it over a whole signal with process. Added in v0.2.4. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
lp = butter(4, "low", 80, 1000)
function lp_block(b, st)
s = st
out = ()
for v in b
s = filter_next(s, v)
out = append(out, s.y)
end for
return (out, s)
end function
p = processor("lp_block", block = 256, state = filter_init(lp), rate = 1000)
y = process(p, x) # or: p.process(x)
print("{p.latency} samples, {p.latency_ms} ms") # 256 samples, 256 ms
256 samples, 256 ms
from signal-processing
How it works
processor(f, [block=256], [state=], [rate=]) — the STATEFUL sibling of block_process, and the offline half of toolkit-signal.md §5. block_process's own comment above names the exact gap this fills: it threads NOTHING between block calls, so an algorithm needing history across a boundary (an IIR's biquad state, overlap-add, a running accumulator) restarts at every block and shows block-edge artifacts. Probed 2026-09-18: a running sum over [1..8] at block=4 comes back [1,3,6,10, 5,11,18,26] — the accumulator visibly resets at sample 4. THE STATE PROTOCOL, AND WHY THIS ONE. block_process's comment correctly says a block-level state protocol should not be invented unilaterally on the way past. It is not invented here: it is the SAME "thread a new state through each call" idiom filter_init/filter_next and kalman_predict/kalman_update already use, lifted from a sample to a block. f(block, state) returns the two-element list (y, next_state); processor seeds the first state and carries each returned one into the next block. Qu has no mutation-of-shared-state primitive, by design, so explicit threading is the only shape available anyway. Stateful is opted into by PASSING state=, not by introspecting f's arity. Arity would have to cope with overloads and would silently pick the wrong protocol when it guessed wrong; a declared state= says what the caller meant, and its absence means the stateless f(block) shape that block_process already has. WHY NOT THE SPEC'S proc = processor(block: 256) { |x| ... } y = proc(s). Both halves were probed against this binary on 2026-09-18 and neither parses or runs. { |x| ... } is a parse error ("expected end of statement, found Op({)") — | is explicitly rejected as a Qu operator and { in expression position is a record literal. And proc(s) calls a value that is not a function, which lands in "unknown function proc". Both would need the open "does Qu grow general object dispatch?" question settled, which is Ahmed's call. So f arrives the way every other higher-order builtin takes it (a name or a function value, via text_arg, which means all three real lambda spellings work), and the handle is applied with process(p, s) / p.process(s).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.