Public repository: timo / feel

Reader

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

docs: ADR-35/36 + ROADMAP — FEEL lambdas (0092)

public

docs: ADR-35/36 + ROADMAP — FEEL lambdas (0092)

Record the two engine increments unlocking DMN-TCK 0092-feel-lambda.

DECISIONS.md:
- ADR-35: typed formal parameters (grammar rule 56) — `FormalParam` rule
  added to `feel.lalrpop`, annotation parsed via `InstanceType` and
  discarded; `Expr::FnDef` and evaluator unchanged.
- ADR-36: first-class built-in function values — `Func::Builtin(String)`,
  `is_builtin()`, updated `Expr::Var` resolution and `invoke` dispatch.

ROADMAP.md:
- Add `### Shipped: FEEL lambda / typed params + first-class built-ins
  (ADR-35/36)` entry with suite delta 2880 → 2896.
- Update `sort(list, function)` deferral bullet to cite 0092-feel-lambda
  testCases 017/018 alongside 0013-sort.

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

modified DECISIONS.md +35 −0

@@ -1733,3 +1733,38 @@
17331733
   expression is still written verbatim to the fixture; feel-core handles it.
17341734
 - **Coverage:** +3 fixture cases (0073 decisions 001–003, all `→ 2`). Suite
17351735
   2887 → 2890.
1736
+
1737
+## ADR-35: Typed formal parameters in function literals (DMN §10.3.2.13, rule 56)
1738
+
1739
+- **Context:** FEEL grammar rule 56 allows formal parameters to carry a type
1740
+  annotation: `function(n: number, s: string) body`. ADR-23 introduced
1741
+  `function(…)` literals with bare-name params only (rule 55 as if rule 56
1742
+  didn't exist). TCK `0092-feel-lambda` uses typed params throughout (e.g.
1743
+  `function (a: number) 1 + a`), so bare-name-only params are a parse failure
1744
+  for every 0092 case.
1745
+- **Decision:** Extend the grammar with a `FormalParam` rule replacing the
1746
+  `Comma<Name>` in the two `FnDef` `TextualExpr` productions:
1747
+  - **Grammar (`feel.lalrpop`):** `FormalParam: String = { <n:Name> => n, <n:Name> ":" InstanceType => n }`. The type annotation is parsed via the existing `InstanceType` nonterminal and then **discarded** — only the parameter name flows into `Expr::FnDef { params: Vec<String> }`. `Expr::FnDef` and the evaluator are unchanged.
1748
+  - **LR(1):** After a `Name`, the one-token lookahead `:` shifts into the typed branch while `,`/`)` reduce to the bare branch — mirrors the `Arg` rule's decision. `build.rs` LALRPOP no-conflict gate verifies.
1749
+  - **`Nb`/`Ep` clones:** `function(...)` literals do not appear in the bracket-free `NbPostfix`/`EpPostfix` chains; only `TextualExpr` needs the change.
1750
+  - **Type enforcement:** This slice binds arguments by name only; arity is already `params.len()`. A typed annotation like `a: number` is parsed and dropped; no runtime type check is performed. This matches the spec semantics for this slice (the type system is advisory at the expression level).
1751
+- **Tests:** `typed_formal_params_parse_and_eval` and `typed_params_closure_and_currying` in `lib.rs` (positional, generic function type annotation, closure with typed param, three-level currying). Unlocks 0092 cases 001–014 and 016.
1752
+- **Consequence:** ADR-23's "typed parameters out of scope" deferral is now resolved. `function(a: number) 1 + a` parses and evaluates correctly.
1753
+
1754
+## ADR-36: First-class built-in function values (DMN §10.3.2.13.1)
1755
+
1756
+- **Context:** The FEEL spec (§10.3.2.13.1) defines invocation on any expression
1757
+  (grammar rule 38: `expression parameters`). A built-in name used as a value
1758
+  expression — e.g. `bkm(abs, sqrt)` where the BKM stores the function and calls
1759
+  `fn1(-5) * fn2(25)` — must yield a callable function value rather than null.
1760
+  TCK `0092-feel-lambda` cases 014 and 016 exercise this directly; case 017/018
1761
+  also rely on it (deferred, needs `sort/2`).
1762
+- **Decision:**
1763
+  - **`function.rs`:** Add `Func::Builtin(String)` variant alongside `Closure` and `Foreign`. The string is the spec name (identical to what `builtins::call` dispatches on, including multi-word joined names like `"string length"`). `Clone` and `PartialEq` (builtins equal by name) added naturally.
1764
+  - **`builtins.rs`:** Add `pub(crate) fn is_builtin(name: &str) -> bool` — a `matches!`-based membership predicate over the full built-in name set. Used by the evaluator to decide whether an unbound name is a built-in reference.
1765
+  - **`eval.rs` `Expr::Var`:** If `ctx.get(name)` is `None` and `is_builtin(name)`, return `Func::Builtin(name)` as the value. A context binding still shadows a built-in (checked first), preserving ADR-23's precedence rule.
1766
+  - **`eval.rs` `invoke`:** New `Func::Builtin(n)` arm dispatches to `builtins::call(n, args, env)`. Wrong-arity or type-error calls return `Some(Error)` from `call`, propagated as error-null; a missing name (impossible in practice) falls back to `Value::Error`.
1767
+  - **`types.rs`:** `Func::Builtin` conforms to `Any` only (same as `Foreign` — arity is not statically known in the type lattice for this slice).
1768
+- **Consequence:** `keyword_phrase_builtin_parses_in_call_position` test updated: the multi-word name `"date and time"` out of call position now correctly returns a `Function` value rather than null (it was null only because the name was unbound; now it resolves to the built-in). Unlocks 0092 cases 014 and 016.
1769
+- **Tests:** `builtin_as_first_class_value` and `builtin_passed_as_argument_and_invoked` in `lib.rs`.
1770
+- **Coverage:** +16 fixture cases (0092 testCases 001–014 incl. 010_a, and 016). Suite 2880 → 2896.

modified ROADMAP.md +18 −2

@@ -186,6 +186,20 @@
186186
 **101 → 109** (the eight `range_006`/`range_007…012` cases). Exercised by the
187187
 `value_position_comparison_test` unit test (incl. an `in`-position regression block).
188188
 
189
+### Shipped: FEEL lambda / typed params + first-class built-ins (ADR-35/36)
190
+
191
+Two increments on top of ADR-23's user-defined-function foundation.
192
+**ADR-35** adds typed formal parameters (`function (a: number) body`, FEEL rule 56)
193
+by extending the grammar's `FnDef` production with a `FormalParam` rule that parses
194
+`name` or `name: Type` via the existing `InstanceType` nonterminal — the annotation
195
+is discarded, only the name flows into `Expr::FnDef`. **ADR-36** makes bare built-in
196
+names (e.g. `abs`, `sqrt`) evaluate to `Value::Function(Func::Builtin(name))` as
197
+first-class values, enabling them to be passed as arguments and invoked through closure
198
+parameters. Together these unlock DMN-TCK `0092-feel-lambda` testCases 001–014 and 016
199
+(17/18; 015 is TCK-commented-out; 017/018 need `sort(list, function)` — deferred below).
200
+Fixture is hand-written (`crates/feel-core/tests/fixtures/0092-feel-lambda.json`),
201
+mirroring the 0030 pattern. **Suite 2880 → 2896**.
202
+
189203
 ### Shipped: Java-style FEEL comments (ADR-34)
190204
 
191205
 Two logos skip patterns on a single `Comment` variant (`//[^\n]*` with
@@ -216,8 +230,10 @@
216230
 ## Smaller, independent deferrals
217231
 
218232
 - **`sort(list, function)`** and the matching-function form of `list replace`
219
-  (`0013-sort`) — need a function-valued comparator; function values already exist
220
-  (ADR-23), so this is a contained built-in addition.
233
+  (`0013-sort`, and `0092-feel-lambda` testCases 017/018) — need a higher-order
234
+  `sort` built-in whose comparator is invoked inside the evaluator. Function values
235
+  already exist (ADR-23) and built-ins are now first-class (ADR-36), so this is a
236
+  contained built-in addition.
221237
 - **General invocation** `expr(args)` / `lib.fn(args)` (e.g. `null()` in
222238
   `1131-feel-function-invocation`) — invoking an arbitrary expression, not just a
223239
   named function. Out of slice (ADR-23).