Public repository: timo / feel

Reader

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

1
[
2
  {
3
    "id": "0092-feel-lambda:001:decision_001_1",
4
    "expression": "{decision_001_2: function (a: number) 1 + a, r: decision_001_2(2)}.r",
5
    "expected": 3.0,
6
    "expected_type": "number",
7
    "comparison": "exact",
8
    "deviation": null,
9
    "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."
10
  },
11
  {
12
    "id": "0092-feel-lambda:002:decision_002_1",
13
    "expression": "{decision_002_2: function (a: number) 1 + a, r: decision_002_2(3)}.r",
14
    "expected": 4.0,
15
    "expected_type": "number",
16
    "comparison": "exact",
17
    "deviation": null,
18
    "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."
19
  },
20
  {
21
    "id": "0092-feel-lambda:003:decision_003_1",
22
    "expression": "{bkm_003_1: function () function (a: number) 1 + a, inner: bkm_003_1(), r: inner(4)}.r",
23
    "expected": 5.0,
24
    "expected_type": "number",
25
    "comparison": "exact",
26
    "deviation": null,
27
    "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'."
28
  },
29
  {
30
    "id": "0092-feel-lambda:004:decision_004_1",
31
    "expression": "{bkm_004_1: function () function (a: number) 1 + a, inner: bkm_004_1(), r: inner(5)}.r",
32
    "expected": 6.0,
33
    "expected_type": "number",
34
    "comparison": "exact",
35
    "deviation": null,
36
    "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."
37
  },
38
  {
39
    "id": "0092-feel-lambda:005:decision_005_1",
40
    "expression": "{bkm_005_1: function (a: number) function (b: number) a * b, inner: bkm_005_1(10), r: inner(2)}.r",
41
    "expected": 20.0,
42
    "expected_type": "number",
43
    "comparison": "exact",
44
    "deviation": null,
45
    "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."
46
  },
47
  {
48
    "id": "0092-feel-lambda:006:decision_006_1",
49
    "expression": "{bkm_006_1: function (a: number) function (b: number) a * b, inner: bkm_006_1(10), r: inner(3)}.r",
50
    "expected": 30.0,
51
    "expected_type": "number",
52
    "comparison": "exact",
53
    "deviation": null,
54
    "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."
55
  },
56
  {
57
    "id": "0092-feel-lambda:007:decision_007_1",
58
    "expression": "{input_007_1: 20, f: function (a: number) a * input_007_1, r: f(5)}.r",
59
    "expected": 100.0,
60
    "expected_type": "number",
61
    "comparison": "exact",
62
    "deviation": null,
63
    "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."
64
  },
65
  {
66
    "id": "0092-feel-lambda:008:decision_008_1",
67
    "expression": "{bkm_008_1: function (a: number) function (a: number, b: number) a * b, inner: bkm_008_1(10), r: inner(2, 3)}.r",
68
    "expected": 6.0,
69
    "expected_type": "number",
70
    "comparison": "exact",
71
    "deviation": null,
72
    "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."
73
  },
74
  {
75
    "id": "0092-feel-lambda:009:decision_009_1",
76
    "expression": "{a: 10, bkm: function (a: number) function (b: number) a * b, inner: bkm(100), r: inner(2)}.r",
77
    "expected": 200.0,
78
    "expected_type": "number",
79
    "comparison": "exact",
80
    "deviation": null,
81
    "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."
82
  },
83
  {
84
    "id": "0092-feel-lambda:010:decision_010_1",
85
    "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",
86
    "expected": 120.0,
87
    "expected_type": "number",
88
    "comparison": "exact",
89
    "deviation": null,
90
    "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."
91
  },
92
  {
93
    "id": "0092-feel-lambda:010_a:decision_010_1_a",
94
    "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",
95
    "expected": 120.0,
96
    "expected_type": "number",
97
    "comparison": "exact",
98
    "deviation": null,
99
    "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."
100
  },
101
  {
102
    "id": "0092-feel-lambda:011:decision_011_1",
103
    "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",
104
    "expected": 5000.0,
105
    "expected_type": "number",
106
    "comparison": "exact",
107
    "deviation": null,
108
    "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."
109
  },
110
  {
111
    "id": "0092-feel-lambda:012:decision_012_1",
112
    "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",
113
    "expected": 5000.0,
114
    "expected_type": "number",
115
    "comparison": "exact",
116
    "deviation": null,
117
    "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."
118
  },
119
  {
120
    "id": "0092-feel-lambda:013:decision_013_1",
121
    "expression": "{ds: function (x) x * 10, bkm: function (fn1, fn2) fn1(5) * fn2(10), r: bkm(ds, ds)}.r",
122
    "expected": 5000.0,
123
    "expected_type": "number",
124
    "comparison": "exact",
125
    "deviation": null,
126
    "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."
127
  },
128
  {
129
    "id": "0092-feel-lambda:014:decision_014_1",
130
    "expression": "{bkm: function (fn1, fn2) fn1(-5) * fn2(25), r: bkm(abs, sqrt)}.r",
131
    "expected": 25.0,
132
    "expected_type": "number",
133
    "comparison": "exact",
134
    "deviation": null,
135
    "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."
136
  },
137
  {
138
    "id": "0092-feel-lambda:016:decision_016_1",
139
    "expression": "{bkm: function (fn1) fn1(10, 2), r: bkm(sqrt)}.r",
140
    "expected": null,
141
    "expected_type": "null",
142
    "comparison": "exact",
143
    "deviation": null,
144
    "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."
145
  },
146
  {
147
    "id": "0092-feel-lambda:017:decision_017_1",
148
    "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",
149
    "expected": ["a", "a", "z", "z"],
150
    "expected_type": "list",
151
    "comparison": "exact",
152
    "deviation": null,
153
    "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."
154
  },
155
  {
156
    "id": "0092-feel-lambda:018:decision_018_1",
157
    "expression": "{bkm_018: function (p1, p2) if p1 = \"a\" then true else false, r: sort([\"a\",\"z\",\"a\",\"z\"], bkm_018)}.r",
158
    "expected": ["a", "a", "z", "z"],
159
    "expected_type": "list",
160
    "comparison": "exact",
161
    "deviation": null,
162
    "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."
163
  }
164
]