Skip to content

OperatorFunc

@defgroup operator_registry Operator Registry @brief Extensible operator registration and dispatch system

The Operator Registry is the key to WAL++'s extensibility. It allows both C++ and Python code to register new operators dynamically.

Operator Registration Model:

@mermaid graph TD A["OperatorRegistry"] -->|register| B["Operator Map"] B --> C["Built-in
50+ ops"] B --> D["Python
Operators"] B --> E["User
Custom"] C --> F["Math"] C --> G["List Ops"] C --> H["Waveform"] D --> I["PyO3 Bridge"] E --> J["Closures"] @endmermaid

Key Features: - Dynamic registration (add operators at runtime) - Unified dispatch (same call for all operator types) - Unevaluated arguments (allows special forms) - Easy Python integration via PyO3

Operator Categories: - Math: +, -, *, /, **, % - Bitwise: band, bor, bxor, lshift, rshift - List: car, cdr, cons, length, list - Array: arange, array, extend - Waveform: signal, signal-names, load, step - Type: type, is?, ... - Control: if, while, for, let - Definition: define, lambda, macro - Special: quote, unquote, eval

See
"Evaluator" for usage
See
"Core API" for public interface

@{ Function signature for all WAL operators

All operators in WAL share this signature:

Value my_operator(SEval& evaluator, const std::vector<Value>& args)

Parameters: - evaluator: Reference to evaluator (for recursive eval, environment access) - args: Unevaluated argument expressions

Return: The computed result value

Unevaluated Arguments: Operators receive arguments unevaluated. This is crucial for: - Special forms (if, define, lambda) that need control flow - Lazy evaluation patterns - Quoting and metaprogramming

Regular operators typically evaluate arguments first:

1
2
3
4
Value builtin_plus(SEval& eval, const std::vector<Value>& args) {
    auto evaluated = eval.eval_args(args);  // Evaluate first
    // ... now compute sum
}

Special forms skip evaluation:

1
2
3
4
5
6
7
8
9
value builtin_if(SEval& eval, const std::vector<Value>& args) {
    // args[0] is condition unevaluated
    auto cond = eval.eval(args[0]);
    if (cond.is_truthy()) {
        return eval.eval(args[1]);  // Evaluate then-branch
    } else {
        return eval.eval(args[2]);  // Evaluate else-branch
    }
}

See
SEval::dispatch_builtin for operator lookup
See
SEval::eval_args for argument evaluation helper