Public repository: timo / feel

Reader

An interpreter of FEEL, written in Rust, with integrations for PostgreSQL, WASM, Lua, and Python.

docs: record ADR-25 (multiple iteration contexts); update README

public

docs: record ADR-25 (multiple iteration contexts); update README

Document the for/some/every multi-context generalization: AST `Vec<(String,
IterSource)>`, the `Comma<IterCtx>` grammar (LR(1), build-gated), Cartesian-
product semantics (rightmost fastest, left-to-right source scoping), non-iterable
→ error-null parity, preserved quantifier short-circuit/provenance, and the slice
detector update. `partial` recorded as out of scope.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Changeset8edb4fbe615479ae27b469af80f55d512bb1fa91
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parentsdbb76c42df1d
Children
Pushlog
by timo via ssh

modified DECISIONS.md +37 −0

@@ -776,6 +776,43 @@
776776
   (the non-interval `in` forms), `instance of`, and `sort`/matching-`list replace` (need a
777777
   function-valued comparator — feasible now that function values exist, ADR-23).
778778
 
779
+## ADR-25: Multiple iteration contexts — `for`/`some`/`every` (FEEL rules 44/46)
780
+
781
+- **Context:** `for`, `some` and `every` were single-context only (`for i in a return …`).
782
+  FEEL allows one *or more* comma-separated iteration contexts (`for i in a, j in b
783
+  return …`; rules 44 & 46), iterating the Cartesian product of the sources. DMN-TCK
784
+  `0033-for-loops` (`for h in heights, w in widths return h * w` → `[20,30,40,60,60,90]`)
785
+  exercises it and was being skipped by the ingester.
786
+- **Decision:** `Expr::For` and `Expr::Quantified` now hold `bindings: Vec<(String,
787
+  IterSource)>` (the tuple idiom already used by `ContextLit`) instead of a single
788
+  `var`/`source`.
789
+  - **Grammar:** one new `IterCtx` rule (`name in source`) fed through the existing
790
+    `Comma<T>` helper over the shared `IterSrc`. A top-level `,` is consumed only by
791
+    `Comma<IterCtx>` — `IterSrc` (`Sum ".." Sum` | `Disjunction`) never eats one — so
792
+    after each context the lookahead is `,` (more) or `return`/`satisfies`, keeping it
793
+    LR(1). The `build.rs` lalrpop gate fails on any conflict; it builds clean, and
794
+    single-context input still parses unchanged.
795
+  - **Semantics (eval):** `eval_for`/`eval_quantified` recurse over the bindings. The
796
+    body/predicate runs over the Cartesian product in declaration order with the
797
+    **rightmost context varying fastest**; each source is resolved in the scope of the
798
+    contexts to its **left**, so a later source may reference an earlier variable
799
+    (`for i in [1,2], j in i..3 return j` = `[1,2,3,2,3]`). `iter_values` is reused
800
+    unchanged (one source, one scope) — the recursion supplies the per-level scope.
801
+  - **Edge cases (parity with single context):** a non-iterable source at *any* level
802
+    makes the whole expression an error-null; the quantifier short-circuit (`some`→true /
803
+    `every`→false on the first dominating tuple) and the sticky error-provenance
804
+    (`saw_unknown`/`tainted`) are preserved across the full product via a small
805
+    `QuantOutcome` enum.
806
+  - **Slice detector:** `fits_slice_grammar` dropped its multi-context reject, now
807
+    captures the subsequent `, name in` variables as bound names, and recognises a
808
+    `, name in` clause as an iterator `in` (not an unsupported membership form).
809
+- **Tests:** feel-core unit tests for `for`/`some`/`every` multi-context (product order,
810
+  left-to-right source scoping, empty-source product, short-circuit), plus the ingested
811
+  DMN-TCK multi-context for-loop cases now kept by the slice detector.
812
+- **Consequence:** rules 44/46 are complete except the `for`-body special variable
813
+  `partial` (the partial result list), which stays out of scope — it is unsupported for a
814
+  single context too, and TCK cases using it remain skipped by the free-identifier scan.
815
+
779816
 ## Adding a wrapper — the host-binding contract
780817
 
781818
 The four wrappers (feel-pg, feel-wasm, feel-py, planned feel-lua) implement the same

modified README.md +4 −1

@@ -27,7 +27,10 @@
2727
 - **Logic:** `and` / `or` / `not(…)` with three-valued (Kleene) semantics.
2828
 - **Control flow:** `if … then … else …`, `for v in src return …`,
2929
   `some/every v in src satisfies …` (over list literals and integer ranges
30
-  `a..b`), and variable references.
30
+  `a..b`), and variable references. `for`/`some`/`every` also take multiple
31
+  comma-separated iteration contexts (`for i in a, j in b return …`; ADR-25) —
32
+  the Cartesian product of the sources, rightmost context varying fastest, with
33
+  each source scoped by the contexts to its left.
3134
 - **Lists & filters (§10.3.2.5):** member / path access `a.b`; the postfix
3235
   `[…]` operator — 1-based index `list[1]` / `list[-1]` (negative-from-end,
3336
   out-of-range → `null`) and Boolean filter `list[item > 5]` (the element is