[
  {
    "id": "0092-feel-lambda:001:decision_001_1",
    "expression": "{decision_001_2: function (a: number) 1 + a, r: decision_001_2(2)}.r",
    "expected": 3.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written (0092 cannot be auto-ingested: decisions return lambdas via <functionDefinition>/<encapsulatedLogic>, not plain <literalExpression>). testCase 001: 'A decision may return a user-defined-function (UDF) lambda'. decision_001_2 is a <literalExpression> returning function(a:number) 1+a; decision_001_1 invokes it with 2 -> 3."
  },
  {
    "id": "0092-feel-lambda:002:decision_002_1",
    "expression": "{decision_002_2: function (a: number) 1 + a, r: decision_002_2(3)}.r",
    "expected": 4.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 002: 'A decision may return a Function Definition lambda'. decision_002_2 is a DMN <functionDefinition> (parameter a:number, body 1+a), semantically identical to a FEEL function literal. Invoked with 3 -> 4."
  },
  {
    "id": "0092-feel-lambda:003:decision_003_1",
    "expression": "{bkm_003_1: function () function (a: number) 1 + a, inner: bkm_003_1(), r: inner(4)}.r",
    "expected": 5.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 003: 'A BKM may return a UDF lambda'. bkm_003_1 is an <encapsulatedLogic> with no formal params whose body is the literal function(a:number) 1+a; calling bkm_003_1() returns that lambda, then inner(4) -> 5. Chained invocation bkm_003_1()(4) is not in-grammar; the intermediate value is bound to 'inner'."
  },
  {
    "id": "0092-feel-lambda:004:decision_004_1",
    "expression": "{bkm_004_1: function () function (a: number) 1 + a, inner: bkm_004_1(), r: inner(5)}.r",
    "expected": 6.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 004: 'A BKM may return a Function Definition lambda'. Same as 003 but the BKM body is a DMN <functionDefinition> instead of a UDF literal — identical semantics. inner(5) -> 6."
  },
  {
    "id": "0092-feel-lambda:005:decision_005_1",
    "expression": "{bkm_005_1: function (a: number) function (b: number) a * b, inner: bkm_005_1(10), r: inner(2)}.r",
    "expected": 20.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 005: 'A BKM may return a UDF lambda with a closed over formal param'. bkm_005_1(a) returns function(b) a*b; bkm_005_1(10) closes over a=10, then inner(2) -> 10*2 = 20."
  },
  {
    "id": "0092-feel-lambda:006:decision_006_1",
    "expression": "{bkm_006_1: function (a: number) function (b: number) a * b, inner: bkm_006_1(10), r: inner(3)}.r",
    "expected": 30.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 006: 'A BKM may return a Function Definition lambda with a closed over formal param'. bkm_006_1(a) returns a <functionDefinition> (b) body a*b; bkm_006_1(10) closes over a=10, inner(3) -> 10*3 = 30."
  },
  {
    "id": "0092-feel-lambda:007:decision_007_1",
    "expression": "{input_007_1: 20, f: function (a: number) a * input_007_1, r: f(5)}.r",
    "expected": 100.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 007 (input_007_1=20): 'A decision may return a UDF lambda with a closed over info requirement value'. decision_007_2 returns function(a) a*input_007_1, closing over input_007_1=20; decision_007_2(5) -> 5*20 = 100."
  },
  {
    "id": "0092-feel-lambda:008:decision_008_1",
    "expression": "{bkm_008_1: function (a: number) function (a: number, b: number) a * b, inner: bkm_008_1(10), r: inner(2, 3)}.r",
    "expected": 6.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 008: 'A lambda's named params take precedence over scope values where the lambda is created'. bkm_008_1(10) closes over a=10 but the inner lambda re-declares param 'a'; when invoked with (2,3), param a=2 overrides the captured a=10, giving 2*3 = 6."
  },
  {
    "id": "0092-feel-lambda:009:decision_009_1",
    "expression": "{a: 10, bkm: function (a: number) function (b: number) a * b, inner: bkm(100), r: inner(2)}.r",
    "expected": 200.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 009: 'A lambda's named params take precedence over scope values where the lambda is invoked'. The outer context has a=10; bkm(100) produces a closure with captured a=100. At invocation time the closure's own a=100 wins over the a=10 in the surrounding scope. inner(2) -> 100*2 = 200."
  },
  {
    "id": "0092-feel-lambda:010:decision_010_1",
    "expression": "{bkm: function (a: number) function (b: number) function (c: number) function (d: number) a * b * c * d, s1: bkm(2), s2: s1(3), s3: s2(4), r: s3(5)}.r",
    "expected": 120.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 010: 'lambdas (UDF) and closures may go more than one level deep (currying)'. bkm_010_1(a) returns a three-level nested lambda; bkm(2)(3)(4) produces function(d) 2*3*4*d; then decision_010_1 invokes that with (5) -> 2*3*4*5 = 120. Chained invocation rewritten as sequential context bindings."
  },
  {
    "id": "0092-feel-lambda:010_a:decision_010_1_a",
    "expression": "{bkm: function (a: number) function (b: number) function (c: number) function (d: number) a * b * c * d, s1: bkm(2), s2: s1(3), s3: s2(4), r: s3(5)}.r",
    "expected": 120.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 010_a: 'lambdas (func defn) and closures may go more than one level deep (currying)'. Same as 010 but the DMN BKM uses nested <functionDefinition> elements instead of nested UDF literals — semantics are identical. 2*3*4*5 = 120."
  },
  {
    "id": "0092-feel-lambda:011:decision_011_1",
    "expression": "{input_011_1: 10, bkm: function (fn1, fn2) fn1(5) * fn2(10), r: bkm(function (a: number) input_011_1 * a, function (b: number) input_011_1 * b)}.r",
    "expected": 5000.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 011 (input_011_1=10): 'lambdas (with closures) may be passed as params'. Two UDF lambdas that close over input_011_1=10 are passed to bkm_011_1. fn1(5)=10*5=50, fn2(10)=10*10=100, result 50*100=5000."
  },
  {
    "id": "0092-feel-lambda:012:decision_012_1",
    "expression": "{bkm_012_2: function (a: number) a * 10, bkm_012_1: function (fn1, fn2) fn1(5) * fn2(10), r: bkm_012_1(bkm_012_2, bkm_012_2)}.r",
    "expected": 5000.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 012: 'BKM may be passed as lambda'. bkm_012_2(a)=a*10 is passed twice to bkm_012_1. fn1(5)=5*10=50, fn2(10)=10*10=100, 50*100=5000."
  },
  {
    "id": "0092-feel-lambda:013:decision_013_1",
    "expression": "{ds: function (x) x * 10, bkm: function (fn1, fn2) fn1(5) * fn2(10), r: bkm(ds, ds)}.r",
    "expected": 5000.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 013: 'Decision Service may be passed as lambda'. decisionService_013_1 takes input_013_1 and returns input_013_1*10 — modelled here as an equivalent UDF lambda ds(x)=x*10. fn1(5)=50, fn2(10)=100, 50*100=5000."
  },
  {
    "id": "0092-feel-lambda:014:decision_014_1",
    "expression": "{bkm: function (fn1, fn2) fn1(-5) * fn2(25), r: bkm(abs, sqrt)}.r",
    "expected": 25.0,
    "expected_type": "number",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 014: 'Built-in function may be passed as lambda'. abs and sqrt are passed as first-class values (ADR-36). fn1(-5)=abs(-5)=5, fn2(25)=sqrt(25)=5, 5*5=25."
  },
  {
    "id": "0092-feel-lambda:016:decision_016_1",
    "expression": "{bkm: function (fn1) fn1(10, 2), r: bkm(sqrt)}.r",
    "expected": null,
    "expected_type": "null",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 016 (errorResult=true): 'Invoking passed lambda with incorrect params still gives error'. sqrt takes one argument; called here with two (10, 2) -> error-null -> null (lenient). Verifies that arity enforcement works for passed built-ins."
  },
  {
    "id": "0092-feel-lambda:017:decision_017_1",
    "expression": "{input_017_1: \"a\", bkm: function (fn1) sort([\"a\",\"z\",\"a\",\"z\"], fn1), r: bkm(function (a: string, b: string) if a = input_017_1 then true else false)}.r",
    "expected": ["a", "a", "z", "z"],
    "expected_type": "list",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written (0092 cannot be auto-ingested: decisions use <encapsulatedLogic>/<functionDefinition>). testCase 017 (input_017_1='a'): 'Local decision scope values may be closed over and used in built-in func'. bkm_017_1(fn1) body is sort([\"a\",\"z\",\"a\",\"z\"], fn1); called with a comparator that closes over input_017_1='a' (precedes when a = input_017_1, i.e. 'a' comes first). Result: [\"a\",\"a\",\"z\",\"z\"]. Unlocked by sort(list, precedes) + ADR-37."
  },
  {
    "id": "0092-feel-lambda:018:decision_018_1",
    "expression": "{bkm_018: function (p1, p2) if p1 = \"a\" then true else false, r: sort([\"a\",\"z\",\"a\",\"z\"], bkm_018)}.r",
    "expected": ["a", "a", "z", "z"],
    "expected_type": "list",
    "comparison": "exact",
    "deviation": null,
    "source": "Hand-written. testCase 018: 'BKM may be passed to sort func'. bkm_018(p1, p2) returns true when p1='a' (i.e. 'a' precedes anything). sort([\"a\",\"z\",\"a\",\"z\"], bkm_018) -> [\"a\",\"a\",\"z\",\"z\"]. Unlocked by sort(list, precedes) + ADR-37."
  }
]
