@almadar/evaluator 2.29.0 → 2.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -268,6 +268,17 @@ type Evaluator$2 = (expr: SExpr, ctx: EvaluationContext) => unknown;
268
268
  * Supports two formats:
269
269
  * - Array of pairs: ["let", [["x", 10], ["y", 20]], body]
270
270
  * - Object style: ["let", {"x": 10, "y": 20}, body]
271
+ *
272
+ * Sequential (`let*`) semantics: each binding's value expression can
273
+ * reference any EARLIER binding in the same `let` via `@<name>` — matches
274
+ * `@almadar/runtime`'s `EffectExecutor` `let` case (its own, independent
275
+ * implementation, which already threads bindings this way) and how `.lolo`
276
+ * is authored in practice: multi-step chains where a later step's formula
277
+ * builds on an earlier one (e.g. std-evade-chase's `chase` tick computing
278
+ * `nc2x` from `nc1x`). Evaluating every binding against the original,
279
+ * unmodified `ctx` (the prior behavior here) left every cross-binding
280
+ * reference unresolved (`undefined`), silently corrupting any `let` with
281
+ * dependent bindings.
271
282
  */
272
283
  declare function evalLet(args: SExpr[], evaluate: Evaluator$2, ctx: EvaluationContext): unknown;
273
284
  /**
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SExpr } from '@almadar/core';
2
2
  export { CORE_BINDINGS, CoreBinding, Expression, ExpressionSchema, ParsedBinding, SExpr, SExprAtom, SExprSchema, collectBindings, getArgs, getOperator, isBinding, isSExpr, isSExprAtom, isSExprCall, isValidBinding, parseBinding, sexpr, walkSExpr } from '@almadar/core';
3
- import { E as EvaluationContext } from './index-BjtK8dP9.js';
4
- export { U as UserContext, c as createChildContext, a as createEffectContext, b as createMinimalContext, e as evalAbs, d as evalAdd, f as evalAnd, g as evalAtomic, h as evalCallService, i as evalCeil, j as evalClamp, k as evalConcat, l as evalCount, m as evalDecrement, n as evalDeref, o as evalDespawn, p as evalDivide, q as evalDo, r as evalEmit, s as evalEmpty, t as evalEqual, u as evalFilter, v as evalFind, w as evalFirst, x as evalFloor, y as evalFn, z as evalGreaterThan, A as evalGreaterThanOrEqual, B as evalIf, C as evalIncludes, D as evalIncrement, F as evalLast, G as evalLessThan, H as evalLessThanOrEqual, I as evalLet, J as evalList, K as evalMap, L as evalMatches, M as evalMax, N as evalMin, O as evalModulo, P as evalMultiply, Q as evalNavigate, R as evalNot, S as evalNotEqual, T as evalNotify, V as evalNth, W as evalOr, X as evalPersist, Y as evalRef, Z as evalRenderUI, _ as evalRound, $ as evalSet, a0 as evalSetDynamic, a1 as evalSpawn, a2 as evalSubtract, a3 as evalSum, a4 as evalSwap, a5 as evalWatch, a6 as evalWhen, a7 as resolveBinding } from './index-BjtK8dP9.js';
3
+ import { E as EvaluationContext } from './index-rPqsFqVO.js';
4
+ export { U as UserContext, c as createChildContext, a as createEffectContext, b as createMinimalContext, e as evalAbs, d as evalAdd, f as evalAnd, g as evalAtomic, h as evalCallService, i as evalCeil, j as evalClamp, k as evalConcat, l as evalCount, m as evalDecrement, n as evalDeref, o as evalDespawn, p as evalDivide, q as evalDo, r as evalEmit, s as evalEmpty, t as evalEqual, u as evalFilter, v as evalFind, w as evalFirst, x as evalFloor, y as evalFn, z as evalGreaterThan, A as evalGreaterThanOrEqual, B as evalIf, C as evalIncludes, D as evalIncrement, F as evalLast, G as evalLessThan, H as evalLessThanOrEqual, I as evalLet, J as evalList, K as evalMap, L as evalMatches, M as evalMax, N as evalMin, O as evalModulo, P as evalMultiply, Q as evalNavigate, R as evalNot, S as evalNotEqual, T as evalNotify, V as evalNth, W as evalOr, X as evalPersist, Y as evalRef, Z as evalRenderUI, _ as evalRound, $ as evalSet, a0 as evalSetDynamic, a1 as evalSpawn, a2 as evalSubtract, a3 as evalSum, a4 as evalSwap, a5 as evalWatch, a6 as evalWhen, a7 as resolveBinding } from './index-rPqsFqVO.js';
5
5
 
6
6
  /**
7
7
  * S-Expression Evaluator
package/dist/index.js CHANGED
@@ -276,11 +276,12 @@ function evalLet(args, evaluate2, ctx) {
276
276
  const body = args[1];
277
277
  const bindingPairs = Array.isArray(rawBindings) ? rawBindings.map((b) => [b[0], b[1]]) : Object.entries(rawBindings);
278
278
  const locals = /* @__PURE__ */ new Map();
279
+ let childCtx = ctx;
279
280
  for (const [name, valueExpr] of bindingPairs) {
280
- const value = evaluate2(valueExpr, ctx);
281
+ const value = evaluate2(valueExpr, childCtx);
281
282
  locals.set(name, value);
283
+ childCtx = createChildContext(ctx, locals);
282
284
  }
283
- const childCtx = createChildContext(ctx, locals);
284
285
  return evaluate2(body, childCtx);
285
286
  }
286
287
  function evalDo(args, evaluate2, ctx) {
@@ -972,6 +973,8 @@ function evalWithItem(expr, evaluate2, ctx, item, index) {
972
973
  let result = evaluate2(expr, childCtx);
973
974
  if (isSExpr(result)) {
974
975
  result = evalWithItem(result, evaluate2, childCtx, item, index);
976
+ } else if (typeof result === "function") {
977
+ result = result(item, evaluate2, childCtx);
975
978
  }
976
979
  return result;
977
980
  }
@@ -3709,6 +3712,7 @@ function evalPathReachable(args, evaluate2, ctx) {
3709
3712
  // SExpressionEvaluator.ts
3710
3713
  var jitCache = /* @__PURE__ */ new Map();
3711
3714
  var MAX_JIT_CACHE_SIZE = 1e3;
3715
+ var UNKNOWN_OPERATOR = /* @__PURE__ */ Symbol("unknown-operator");
3712
3716
  var SExpressionEvaluator = class {
3713
3717
  /**
3714
3718
  * Evaluate an S-expression in the given context.
@@ -3729,11 +3733,18 @@ var SExpressionEvaluator = class {
3729
3733
  }
3730
3734
  return out;
3731
3735
  }
3736
+ if (Array.isArray(expr)) {
3737
+ return expr.map((item) => this.evaluate(item, ctx));
3738
+ }
3732
3739
  return expr;
3733
3740
  }
3734
3741
  const op = getOperator(expr);
3735
3742
  const args = getArgs(expr);
3736
- return this.dispatchOperator(op, args, ctx);
3743
+ const result = this.dispatchOperator(op, args, ctx);
3744
+ if (result === UNKNOWN_OPERATOR) {
3745
+ return expr.map((item) => this.evaluate(item, ctx));
3746
+ }
3747
+ return result;
3737
3748
  }
3738
3749
  isPlainObject(value) {
3739
3750
  return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date) && Object.getPrototypeOf(value) === Object.prototype;
@@ -4581,8 +4592,7 @@ var SExpressionEvaluator = class {
4581
4592
  case "integration/github-create-issue":
4582
4593
  return evalIntegrationGithubCreateIssue(args, evaluate2, ctx);
4583
4594
  default:
4584
- console.warn(`Unknown operator: ${op}`);
4585
- return void 0;
4595
+ return UNKNOWN_OPERATOR;
4586
4596
  }
4587
4597
  }
4588
4598
  };