pub fn eval_const_expr(source: &str) -> Result<Value, EmbeddingError>Expand description
Evaluate a constant expression by compiling it as a one-binding
program: what a comprehension source such as partitions("*\/4", 1000)
goes through. Cached by source text, so the same text compiles once
per process (SRD 113 §5.2). An expression that reaches a dynamic
input is a lifecycle error. The compile, when there is one, is
recorded in a ledger of its own; eval_const_expr_for charges
it to a tree’s.
§Examples
use polydat::dsl::compile::eval_const_expr;
let v = eval_const_expr("4 * 4").unwrap();
assert_eq!(v.as_u64(), 16); // both int literals → u64_mul
let v = eval_const_expr("4.0 * 4.0").unwrap();
assert_eq!(v.as_f64(), 16.0); // both float literals → f64_mul