Files
Stefan 929cb3e3df refactor(engine): pass the evaluation clock and random streams explicitly instead of thread-local scopes
- zen_expression::clock: Clock is now plain per-evaluation state (now,
  timezone, seed, per-row and per-item random streams in a RefCell
  arena), and EvalContext pairs an Rc<Clock> with the row mapping of
  the current call (direct, one stream, picked rows, loop items). The
  thread-local current clock, Origin/Origins, set_row/at_row and the
  stream map lookups are gone.
- the compiled engine builds the context once per evaluation
  (pinning::single / pinning::batch) and carries it in
  NodeHandlerExtensions; graph states, bounds, loops, sub-decisions,
  tables and policies derive row/item contexts with rows()/at()/items()
  and pass them down.
- lane runs (LaneRunner, Session, kernels, cells), builtins (At),
  date helpers and typed programs take the context or its clock
  explicitly; rand draws from the stream of the lane's row.
- function hosts install Date/Math.random once per runtime and point
  them at the call's context with a scoped JsClock slot (v1 scripts,
  v1 batch sessions, v2 handlers, rows and zen.evaluate).
- Workspace gains evaluate_pinned / evaluate_batch_pinned /
  evaluate_columns_pinned that read now/timezone/seed from
  EvaluationOptions.
- d(...) with a zone-dependent argument is no longer folded at compile
  time; typed lowering folds only zone-independent date texts and
  checks the rest at run time with the evaluation's zone.
- the interpreted engine and the stack VM use the host clock and
  unseeded fastrand as on release/2.2; functions/internal.rs is back
  to release/2.2.
- tests: interleaved evaluations on one thread and on two threads see
  only their own clock and stream.
2026-11-05 18:12:20 +01:00
..
2026-10-21 17:48:01 +02:00

ZEN Expression Language

The expression language of ZEN Engine, the open-source Business Rules Engine (BRE) from GoRules.

License: MIT crates.io

ZEN expressions are readable by business users and fast enough for hot paths: a complete language for conditions, calculations and data transformation, with lexer, parser, compiler, VM, type checking and editor completions included in this crate.

use serde_json::json;
use zen_expression::evaluate_expression;

fn main() {
    let result = evaluate_expression(
        "sum(items) * multiplier",
        json!({ "items": [10, 20, 30], "multiplier": 2 }).into(),
    )
    .unwrap();
    // => 120
}

Reusable expressions compile once via compile_expression and evaluate repeatedly against different contexts.

Resources

License

MIT License