@elaraai/east 1.0.80 → 1.0.82

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.
Files changed (150) hide show
  1. package/dist/src/builtins.d.ts +1 -1
  2. package/dist/src/builtins.d.ts.map +1 -1
  3. package/dist/src/builtins.js +19 -0
  4. package/dist/src/builtins.js.map +1 -1
  5. package/dist/src/codegen/spellings.d.ts.map +1 -1
  6. package/dist/src/codegen/spellings.js +3 -0
  7. package/dist/src/codegen/spellings.js.map +1 -1
  8. package/dist/src/comparison.d.ts +54 -0
  9. package/dist/src/comparison.d.ts.map +1 -1
  10. package/dist/src/comparison.equivalent.spec.d.ts +6 -0
  11. package/dist/src/comparison.equivalent.spec.d.ts.map +1 -0
  12. package/dist/src/comparison.equivalent.spec.js +130 -0
  13. package/dist/src/comparison.equivalent.spec.js.map +1 -0
  14. package/dist/src/comparison.js +93 -20
  15. package/dist/src/comparison.js.map +1 -1
  16. package/dist/src/compile/builtins/array.d.ts +2 -1
  17. package/dist/src/compile/builtins/array.d.ts.map +1 -1
  18. package/dist/src/compile/builtins/array.js +35 -0
  19. package/dist/src/compile/builtins/array.js.map +1 -1
  20. package/dist/src/compile/builtins/dict.d.ts +1 -0
  21. package/dist/src/compile/builtins/dict.d.ts.map +1 -1
  22. package/dist/src/compile/builtins/dict.js +25 -0
  23. package/dist/src/compile/builtins/dict.js.map +1 -1
  24. package/dist/src/compile/builtins/set.d.ts +1 -0
  25. package/dist/src/compile/builtins/set.d.ts.map +1 -1
  26. package/dist/src/compile/builtins/set.js +25 -0
  27. package/dist/src/compile/builtins/set.js.map +1 -1
  28. package/dist/src/compile/builtins/tree.d.ts +32 -0
  29. package/dist/src/compile/builtins/tree.d.ts.map +1 -0
  30. package/dist/src/compile/builtins/tree.js +108 -0
  31. package/dist/src/compile/builtins/tree.js.map +1 -0
  32. package/dist/src/compile/functions.d.ts.map +1 -1
  33. package/dist/src/compile/functions.js +4 -4
  34. package/dist/src/compile/functions.js.map +1 -1
  35. package/dist/src/compile/runtime.d.ts +12 -15
  36. package/dist/src/compile/runtime.d.ts.map +1 -1
  37. package/dist/src/compile/runtime.js +19 -16
  38. package/dist/src/compile/runtime.js.map +1 -1
  39. package/dist/src/compile.signature.spec.d.ts +6 -0
  40. package/dist/src/compile.signature.spec.d.ts.map +1 -0
  41. package/dist/src/compile.signature.spec.js +53 -0
  42. package/dist/src/compile.signature.spec.js.map +1 -0
  43. package/dist/src/expr/array.d.ts +158 -81
  44. package/dist/src/expr/array.d.ts.map +1 -1
  45. package/dist/src/expr/array.js +68 -51
  46. package/dist/src/expr/array.js.map +1 -1
  47. package/dist/src/expr/ast.d.ts.map +1 -1
  48. package/dist/src/expr/ast.js +13 -0
  49. package/dist/src/expr/ast.js.map +1 -1
  50. package/dist/src/expr/blob.d.ts +8 -8
  51. package/dist/src/expr/blob.js +8 -8
  52. package/dist/src/expr/block.d.ts +18 -5
  53. package/dist/src/expr/block.d.ts.map +1 -1
  54. package/dist/src/expr/block.js +19 -0
  55. package/dist/src/expr/block.js.map +1 -1
  56. package/dist/src/expr/boolean.d.ts +10 -10
  57. package/dist/src/expr/boolean.js +10 -10
  58. package/dist/src/expr/datetime.d.ts +28 -28
  59. package/dist/src/expr/datetime.js +28 -28
  60. package/dist/src/expr/dict.d.ts +101 -51
  61. package/dist/src/expr/dict.d.ts.map +1 -1
  62. package/dist/src/expr/dict.js +97 -36
  63. package/dist/src/expr/dict.js.map +1 -1
  64. package/dist/src/expr/float.d.ts +23 -23
  65. package/dist/src/expr/float.js +23 -23
  66. package/dist/src/expr/integer.d.ts +17 -17
  67. package/dist/src/expr/integer.js +11 -11
  68. package/dist/src/expr/libs/array.d.ts +6 -6
  69. package/dist/src/expr/libs/array.js +6 -6
  70. package/dist/src/expr/libs/blob.d.ts +2 -2
  71. package/dist/src/expr/libs/blob.js +2 -2
  72. package/dist/src/expr/libs/datetime.d.ts +25 -25
  73. package/dist/src/expr/libs/datetime.js +25 -25
  74. package/dist/src/expr/libs/dict.d.ts +2 -2
  75. package/dist/src/expr/libs/dict.js +2 -2
  76. package/dist/src/expr/libs/float.d.ts +15 -15
  77. package/dist/src/expr/libs/float.js +15 -15
  78. package/dist/src/expr/libs/integer.d.ts +12 -12
  79. package/dist/src/expr/libs/integer.js +12 -12
  80. package/dist/src/expr/libs/set.d.ts +2 -2
  81. package/dist/src/expr/libs/set.js +2 -2
  82. package/dist/src/expr/libs/string.d.ts +4 -4
  83. package/dist/src/expr/libs/string.js +4 -4
  84. package/dist/src/expr/recursive.d.ts +22 -5
  85. package/dist/src/expr/recursive.d.ts.map +1 -1
  86. package/dist/src/expr/recursive.js +22 -5
  87. package/dist/src/expr/recursive.js.map +1 -1
  88. package/dist/src/expr/ref.d.ts +5 -5
  89. package/dist/src/expr/ref.js +5 -5
  90. package/dist/src/expr/set.d.ts +96 -51
  91. package/dist/src/expr/set.d.ts.map +1 -1
  92. package/dist/src/expr/set.js +85 -29
  93. package/dist/src/expr/set.js.map +1 -1
  94. package/dist/src/expr/string.d.ts +28 -28
  95. package/dist/src/expr/string.js +28 -28
  96. package/dist/src/expr/struct.d.ts.map +1 -1
  97. package/dist/src/expr/struct.js +2 -2
  98. package/dist/src/expr/variant.d.ts +12 -12
  99. package/dist/src/expr/variant.js +7 -7
  100. package/dist/src/function_symbols.d.ts +28 -0
  101. package/dist/src/function_symbols.d.ts.map +1 -0
  102. package/dist/src/function_symbols.js +28 -0
  103. package/dist/src/function_symbols.js.map +1 -0
  104. package/dist/src/location.d.ts +32 -0
  105. package/dist/src/location.d.ts.map +1 -1
  106. package/dist/src/location.js +38 -0
  107. package/dist/src/location.js.map +1 -1
  108. package/dist/src/location.spec.js +89 -1
  109. package/dist/src/location.spec.js.map +1 -1
  110. package/dist/src/runner_protocol.d.ts +46 -5
  111. package/dist/src/runner_protocol.d.ts.map +1 -1
  112. package/dist/src/runner_protocol.js +24 -5
  113. package/dist/src/runner_protocol.js.map +1 -1
  114. package/dist/src/serialization/beast2/index.d.ts +1 -0
  115. package/dist/src/serialization/beast2/index.d.ts.map +1 -1
  116. package/dist/src/serialization/beast2/index.js +1 -0
  117. package/dist/src/serialization/beast2/index.js.map +1 -1
  118. package/dist/src/serialization/beast2/v5/canonical.d.ts +101 -0
  119. package/dist/src/serialization/beast2/v5/canonical.d.ts.map +1 -0
  120. package/dist/src/serialization/beast2/v5/canonical.js +436 -0
  121. package/dist/src/serialization/beast2/v5/canonical.js.map +1 -0
  122. package/dist/src/serialization/beast2/v5/canonical.spec.d.ts +6 -0
  123. package/dist/src/serialization/beast2/v5/canonical.spec.d.ts.map +1 -0
  124. package/dist/src/serialization/beast2/v5/canonical.spec.js +124 -0
  125. package/dist/src/serialization/beast2/v5/canonical.spec.js.map +1 -0
  126. package/dist/src/serialization/beast2/v5/elements.d.ts +3 -1
  127. package/dist/src/serialization/beast2/v5/elements.d.ts.map +1 -1
  128. package/dist/src/serialization/beast2/v5/elements.js +7 -2
  129. package/dist/src/serialization/beast2/v5/elements.js.map +1 -1
  130. package/dist/src/serialization/beast2/v5/elements.spec.js +1 -1
  131. package/dist/src/serialization/beast2/v5/elements.spec.js.map +1 -1
  132. package/dist/src/serialization/beast2/v5/intake.d.ts +98 -0
  133. package/dist/src/serialization/beast2/v5/intake.d.ts.map +1 -0
  134. package/dist/src/serialization/beast2/v5/intake.js +462 -0
  135. package/dist/src/serialization/beast2/v5/intake.js.map +1 -0
  136. package/dist/src/serialization/beast2/v5/intake.spec.d.ts +6 -0
  137. package/dist/src/serialization/beast2/v5/intake.spec.d.ts.map +1 -0
  138. package/dist/src/serialization/beast2/v5/intake.spec.js +202 -0
  139. package/dist/src/serialization/beast2/v5/intake.spec.js.map +1 -0
  140. package/dist/src/serialization/beast2/v5/runs.d.ts +6 -4
  141. package/dist/src/serialization/beast2/v5/runs.d.ts.map +1 -1
  142. package/dist/src/serialization/beast2/v5/runs.js +31 -5
  143. package/dist/src/serialization/beast2/v5/runs.js.map +1 -1
  144. package/dist/src/serialization/beast2/v5/runs.spec.js +23 -3
  145. package/dist/src/serialization/beast2/v5/runs.spec.js.map +1 -1
  146. package/dist/src/serialization/index.d.ts +1 -1
  147. package/dist/src/serialization/index.d.ts.map +1 -1
  148. package/dist/src/serialization/index.js +1 -1
  149. package/dist/src/serialization/index.js.map +1 -1
  150. package/package.json +1 -1
@@ -17,7 +17,7 @@ export default {
17
17
  * const formatComma = East.function([IntegerType], StringType, ($, x) => {
18
18
  * $.return(East.Integer.printCommaSeperated(x));
19
19
  * });
20
- * const compiled = East.compile(formatComma.toIR(), []);
20
+ * const compiled = East.compile(formatComma, []);
21
21
  * compiled(1234567n); // "1,234,567"
22
22
  * compiled(1000n); // "1,000"
23
23
  * compiled(-5432n); // "-5,432"
@@ -59,7 +59,7 @@ export default {
59
59
  * const formatCurrency = East.function([IntegerType], StringType, ($, x) => {
60
60
  * $.return(East.Integer.printCurrency(x));
61
61
  * });
62
- * const compiled = East.compile(formatCurrency.toIR(), []);
62
+ * const compiled = East.compile(formatCurrency, []);
63
63
  * compiled(1234n); // "$1,234"
64
64
  * compiled(-42n); // "-$42"
65
65
  * compiled(1000000n); // "$1,000,000"
@@ -108,7 +108,7 @@ export default {
108
108
  * const formatCompact = East.function([IntegerType], StringType, ($, x) => {
109
109
  * $.return(East.Integer.printCompact(x));
110
110
  * });
111
- * const compiled = East.compile(formatCompact.toIR(), []);
111
+ * const compiled = East.compile(formatCompact, []);
112
112
  * compiled(1500n); // "1.5K"
113
113
  * compiled(2500000n); // "2.5M"
114
114
  * compiled(3140000000n); // "3.14B"
@@ -163,7 +163,7 @@ export default {
163
163
  * const formatSI = East.function([IntegerType], StringType, ($, x) => {
164
164
  * $.return(East.Integer.printCompactSI(x));
165
165
  * });
166
- * const compiled = East.compile(formatSI.toIR(), []);
166
+ * const compiled = East.compile(formatSI, []);
167
167
  * compiled(1500n); // "1.5k"
168
168
  * compiled(2500000n); // "2.5M"
169
169
  * compiled(3140000000n); // "3.14G"
@@ -211,7 +211,7 @@ export default {
211
211
  * const formatComputing = East.function([IntegerType], StringType, ($, x) => {
212
212
  * $.return(East.Integer.printCompactComputing(x));
213
213
  * });
214
- * const compiled = East.compile(formatComputing.toIR(), []);
214
+ * const compiled = East.compile(formatComputing, []);
215
215
  * compiled(1536n); // "1.5ki" (1536 bytes = 1.5 KiB)
216
216
  * compiled(2621440n); // "2.5Mi" (2.5 MiB)
217
217
  * compiled(3221225472n); // "3Gi" (3 GiB)
@@ -255,7 +255,7 @@ export default {
255
255
  * const formatOrdinal = East.function([IntegerType], StringType, ($, x) => {
256
256
  * $.return(East.Integer.printOrdinal(x));
257
257
  * });
258
- * const compiled = East.compile(formatOrdinal.toIR(), []);
258
+ * const compiled = East.compile(formatOrdinal, []);
259
259
  * compiled(1n); // "1st"
260
260
  * compiled(2n); // "2nd"
261
261
  * compiled(3n); // "3rd"
@@ -289,7 +289,7 @@ export default {
289
289
  * const countDigits = East.function([IntegerType], IntegerType, ($, x) => {
290
290
  * $.return(East.Integer.digitCount(x));
291
291
  * });
292
- * const compiled = East.compile(countDigits.toIR(), []);
292
+ * const compiled = East.compile(countDigits, []);
293
293
  * compiled(0n); // 1n
294
294
  * compiled(42n); // 2n
295
295
  * compiled(-1234n); // 4n
@@ -312,7 +312,7 @@ export default {
312
312
  * const roundNearest = East.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
313
313
  * $.return(East.Integer.roundNearest(x, step));
314
314
  * });
315
- * const compiled = East.compile(roundNearest.toIR(), []);
315
+ * const compiled = East.compile(roundNearest, []);
316
316
  * compiled(17n, 5n); // 15n
317
317
  * compiled(18n, 5n); // 20n
318
318
  * compiled(-17n, 5n); // -15n
@@ -346,7 +346,7 @@ export default {
346
346
  * const roundUp = East.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
347
347
  * $.return(East.Integer.roundUp(x, step));
348
348
  * });
349
- * const compiled = East.compile(roundUp.toIR(), []);
349
+ * const compiled = East.compile(roundUp, []);
350
350
  * compiled(17n, 5n); // 20n
351
351
  * compiled(15n, 5n); // 15n (already exact)
352
352
  * compiled(-17n, 5n); // -15n (towards zero for negatives)
@@ -376,7 +376,7 @@ export default {
376
376
  * const roundDown = East.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
377
377
  * $.return(East.Integer.roundDown(x, step));
378
378
  * });
379
- * const compiled = East.compile(roundDown.toIR(), []);
379
+ * const compiled = East.compile(roundDown, []);
380
380
  * compiled(17n, 5n); // 15n
381
381
  * compiled(15n, 5n); // 15n (already exact)
382
382
  * compiled(-17n, 5n); // -20n (away from zero for negatives)
@@ -406,7 +406,7 @@ export default {
406
406
  * const roundTruncate = East.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
407
407
  * $.return(East.Integer.roundTruncate(x, step));
408
408
  * });
409
- * const compiled = East.compile(roundTruncate.toIR(), []);
409
+ * const compiled = East.compile(roundTruncate, []);
410
410
  * compiled(17n, 5n); // 15n
411
411
  * compiled(-17n, 5n); // -15n
412
412
  * compiled(3n, 5n); // 0n
@@ -432,7 +432,7 @@ export default {
432
432
  * const formatPercent = East.function([IntegerType], StringType, ($, x) => {
433
433
  * $.return(East.Integer.printPercentage(x));
434
434
  * });
435
- * const compiled = East.compile(formatPercent.toIR(), []);
435
+ * const compiled = East.compile(formatPercent, []);
436
436
  * compiled(45n); // "45%"
437
437
  * compiled(100n); // "100%"
438
438
  * compiled(-25n); // "-25%"
@@ -34,7 +34,7 @@ declare const _default: {
34
34
  * ($, i) => Expr.str`key${i}`
35
35
  * ));
36
36
  * });
37
- * const compiled = East.compile(makeSet.toIR(), []);
37
+ * const compiled = East.compile(makeSet, []);
38
38
  * compiled(); // Set(["key0", "key1", "key2"])
39
39
  * ```
40
40
  *
@@ -49,7 +49,7 @@ declare const _default: {
49
49
  * ($, key) => null // Ignore duplicates
50
50
  * ));
51
51
  * });
52
- * const compiled = East.compile(makeSetConflict.toIR(), []);
52
+ * const compiled = East.compile(makeSetConflict, []);
53
53
  * compiled(); // Set([0n, 1n, 2n])
54
54
  * ```
55
55
  */
@@ -33,7 +33,7 @@ export default {
33
33
  * ($, i) => Expr.str`key${i}`
34
34
  * ));
35
35
  * });
36
- * const compiled = East.compile(makeSet.toIR(), []);
36
+ * const compiled = East.compile(makeSet, []);
37
37
  * compiled(); // Set(["key0", "key1", "key2"])
38
38
  * ```
39
39
  *
@@ -48,7 +48,7 @@ export default {
48
48
  * ($, key) => null // Ignore duplicates
49
49
  * ));
50
50
  * });
51
- * const compiled = East.compile(makeSetConflict.toIR(), []);
51
+ * const compiled = East.compile(makeSetConflict, []);
52
52
  * compiled(); // Set([0n, 1n, 2n])
53
53
  * ```
54
54
  */
@@ -22,7 +22,7 @@ declare const _default: {
22
22
  * const formatError = East.function([StringType, ArrayType(StackFrameType)], StringType, ($, msg, stack) => {
23
23
  * $.return(East.printError(msg, stack));
24
24
  * });
25
- * const compiled = East.compile(formatError.toIR(), []);
25
+ * const compiled = East.compile(formatError, []);
26
26
  * const result = compiled("Division by zero", [
27
27
  * { filename: "app.ts", line: 42n, column: 10n },
28
28
  * { filename: "main.ts", line: 15n, column: 5n }
@@ -51,7 +51,7 @@ declare const _default: {
51
51
  * const toJson = East.function([PersonType], StringType, ($, person) => {
52
52
  * $.return(East.String.printJson(person));
53
53
  * });
54
- * const compiled = East.compile(toJson.toIR(), []);
54
+ * const compiled = East.compile(toJson, []);
55
55
  * compiled({ name: "Alice", age: 30n }); // '{"name":"Alice","age":"30"}' — an Integer is a decimal string
56
56
  * ```
57
57
  *
@@ -61,7 +61,7 @@ declare const _default: {
61
61
  * const arrayToJson = East.function([ArrayType(IntegerType)], StringType, ($, arr) => {
62
62
  * $.return(East.String.printJson(arr));
63
63
  * });
64
- * const compiled = East.compile(arrayToJson.toIR(), []);
64
+ * const compiled = East.compile(arrayToJson, []);
65
65
  * compiled([1n, 2n, 3n]); // '["1","2","3"]'
66
66
  * ```
67
67
  *
@@ -73,7 +73,7 @@ declare const _default: {
73
73
  * const optionToJson = East.function([OptionType(StringType)], StringType, ($, note) => {
74
74
  * $.return(East.String.printJson(note));
75
75
  * });
76
- * const compiled = East.compile(optionToJson.toIR(), []);
76
+ * const compiled = East.compile(optionToJson, []);
77
77
  * compiled(none); // 'null'
78
78
  * compiled(some("x")); // '"x"'
79
79
  * ```
@@ -21,7 +21,7 @@ export default {
21
21
  * const formatError = East.function([StringType, ArrayType(StackFrameType)], StringType, ($, msg, stack) => {
22
22
  * $.return(East.printError(msg, stack));
23
23
  * });
24
- * const compiled = East.compile(formatError.toIR(), []);
24
+ * const compiled = East.compile(formatError, []);
25
25
  * const result = compiled("Division by zero", [
26
26
  * { filename: "app.ts", line: 42n, column: 10n },
27
27
  * { filename: "main.ts", line: 15n, column: 5n }
@@ -48,7 +48,7 @@ export default {
48
48
  * const toJson = East.function([PersonType], StringType, ($, person) => {
49
49
  * $.return(East.String.printJson(person));
50
50
  * });
51
- * const compiled = East.compile(toJson.toIR(), []);
51
+ * const compiled = East.compile(toJson, []);
52
52
  * compiled({ name: "Alice", age: 30n }); // '{"name":"Alice","age":"30"}' — an Integer is a decimal string
53
53
  * ```
54
54
  *
@@ -58,7 +58,7 @@ export default {
58
58
  * const arrayToJson = East.function([ArrayType(IntegerType)], StringType, ($, arr) => {
59
59
  * $.return(East.String.printJson(arr));
60
60
  * });
61
- * const compiled = East.compile(arrayToJson.toIR(), []);
61
+ * const compiled = East.compile(arrayToJson, []);
62
62
  * compiled([1n, 2n, 3n]); // '["1","2","3"]'
63
63
  * ```
64
64
  *
@@ -70,7 +70,7 @@ export default {
70
70
  * const optionToJson = East.function([OptionType(StringType)], StringType, ($, note) => {
71
71
  * $.return(East.String.printJson(note));
72
72
  * });
73
- * const compiled = East.compile(optionToJson.toIR(), []);
73
+ * const compiled = East.compile(optionToJson, []);
74
74
  * compiled(none); // 'null'
75
75
  * compiled(some("x")); // '"x"'
76
76
  * ```
@@ -29,14 +29,31 @@ import type { ExprType, SubtypeExprOrValue } from "./types.js";
29
29
  * cons: StructType({ head: IntegerType, tail: self })
30
30
  * }));
31
31
  *
32
- * // Create and work with linked lists
32
+ * // Sum a list by walking it in a loop, unwrapping one node at a time
33
33
  * const sumList = East.function([LinkedListType], IntegerType, ($, list) => {
34
- * $.return(list.unwrap().match({
35
- * nil: ($) => 0n,
36
- * cons: ($, node) => node.head.add(sumList(node.tail))
37
- * }));
34
+ * const sum = $.let(0n);
35
+ * const current = $.let(list, LinkedListType);
36
+ * $.while(true, ($, label) => {
37
+ * $.match(current.unwrap(), {
38
+ * nil: ($) => {
39
+ * $.break(label);
40
+ * },
41
+ * cons: ($, node) => {
42
+ * $.assign(sum, sum.add(node.head));
43
+ * $.assign(current, node.tail);
44
+ * },
45
+ * });
46
+ * });
47
+ * return sum;
38
48
  * });
49
+ * const compiled = East.compile(sumList, []);
50
+ * compiled(variant("cons", { head: 1n, tail: variant("cons", { head: 2n, tail: variant("cons", { head: 3n, tail: variant("nil", null) }) }) })); // 6n
39
51
  * ```
52
+ *
53
+ * A function cannot call itself by its own name — the `const` is not yet
54
+ * assigned while its body is built. Walk a recursive value with a loop as
55
+ * above, build one from flat parent-keyed data with `toTree`, or recurse
56
+ * through a function held in a variable (`$.let`, then `$.assign`).
40
57
  */
41
58
  export declare class RecursiveExpr<T> extends Expr<RecursiveType<T>> {
42
59
  private nodeType;
@@ -1 +1 @@
1
- {"version":3,"file":"recursive.d.ts","sourceRoot":"","sources":["../../../src/expr/recursive.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAA4B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAG/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,aAAa,CAAC,C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tB,OAAO,EAAE,MAAM,GACd,aAAa,CAAC,CAAC,CAAC;CAUpB"}
@@ -25,14 +25,31 @@ import { valueOrExprToAstTyped } from "./ast.js";
25
25
  * cons: StructType({ head: IntegerType, tail: self })
26
26
  * }));
27
27
  *
28
- * // Create and work with linked lists
28
+ * // Sum a list by walking it in a loop, unwrapping one node at a time
29
29
  * const sumList = East.function([LinkedListType], IntegerType, ($, list) => {
30
- * $.return(list.unwrap().match({
31
- * nil: ($) => 0n,
32
- * cons: ($, node) => node.head.add(sumList(node.tail))
33
- * }));
30
+ * const sum = $.let(0n);
31
+ * const current = $.let(list, LinkedListType);
32
+ * $.while(true, ($, label) => {
33
+ * $.match(current.unwrap(), {
34
+ * nil: ($) => {
35
+ * $.break(label);
36
+ * },
37
+ * cons: ($, node) => {
38
+ * $.assign(sum, sum.add(node.head));
39
+ * $.assign(current, node.tail);
40
+ * },
41
+ * });
42
+ * });
43
+ * return sum;
34
44
  * });
45
+ * const compiled = East.compile(sumList, []);
46
+ * compiled(variant("cons", { head: 1n, tail: variant("cons", { head: 2n, tail: variant("cons", { head: 3n, tail: variant("nil", null) }) }) })); // 6n
35
47
  * ```
48
+ *
49
+ * A function cannot call itself by its own name — the `const` is not yet
50
+ * assigned while its body is built. Walk a recursive value with a loop as
51
+ * above, build one from flat parent-keyed data with `toTree`, or recurse
52
+ * through a function held in a variable (`$.let`, then `$.assign`).
36
53
  */
37
54
  export class RecursiveExpr extends Expr {
38
55
  nodeType;
@@ -1 +1 @@
1
- {"version":3,"file":"recursive.js","sourceRoot":"","sources":["../../../src/expr/recursive.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAe,MAAM,WAAW,CAAC;AAExE,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,OAAO,aAAiB,SAAQ,IAAsB;IACtC;IAApB,YAAoB,QAAW,EAAE,GAAQ,EAAE,OAAe;QACxD,KAAK,CAAC,GAAG,CAAC,IAAwB,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QADhC,aAAQ,GAAR,QAAQ,CAAG;IAE/B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM;QACJ,MAAM,SAAS,GAAQ;YACrB,QAAQ,EAAE,iBAAiB;YAC3B,IAAI,EAAE,IAAI,CAAC,QAAuB;YAClC,MAAM,EAAE,eAAe,EAAE;YACzB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC;SACvB,CAAC;QACF,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC,SAAS,CAAgB,CAAC;IACvD,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,IAAI,CACT,KAA4B,EAC5B,IAAsB,EACtB,OAAe;QAEf,MAAM,QAAQ,GAAG,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,IAAmB,CAAC,CAAC;QACxE,MAAM,OAAO,GAAQ;YACnB,QAAQ,EAAE,eAAe;YACzB,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,EAAE;YACzB,KAAK,EAAE,QAAQ;SAChB,CAAC;QACF,OAAO,OAAO,CAAC,OAAO,CAAqB,CAAC;IAC9C,CAAC;CACF"}
@@ -20,7 +20,7 @@ import type { ExprType, SubtypeExprOrValue } from "./types.js";
20
20
  * const counter = $.let(East.value(ref(42n)));
21
21
  * $.return(counter.get());
22
22
  * });
23
- * const compiled = East.compile(getRefValue.toIR(), []);
23
+ * const compiled = East.compile(getRefValue, []);
24
24
  * compiled(); // 42n
25
25
  * ```
26
26
  *
@@ -32,7 +32,7 @@ import type { ExprType, SubtypeExprOrValue } from "./types.js";
32
32
  * $(counter.update(newValue));
33
33
  * $.return(counter.get());
34
34
  * });
35
- * const compiled = East.compile(updateRef.toIR(), []);
35
+ * const compiled = East.compile(updateRef, []);
36
36
  * compiled(100n); // 100n
37
37
  * ```
38
38
  */
@@ -50,7 +50,7 @@ export declare class RefExpr<T extends any> extends Expr<RefType<T>> {
50
50
  * const counter = $.let(East.value(ref(42n)));
51
51
  * $.return(counter.get());
52
52
  * });
53
- * const compiled = East.compile(getRefValue.toIR(), []);
53
+ * const compiled = East.compile(getRefValue, []);
54
54
  * compiled(); // 42n
55
55
  * ```
56
56
  */
@@ -68,7 +68,7 @@ export declare class RefExpr<T extends any> extends Expr<RefType<T>> {
68
68
  * $(counter.update(newValue));
69
69
  * $.return(counter.get());
70
70
  * });
71
- * const compiled = East.compile(updateRef.toIR(), []);
71
+ * const compiled = East.compile(updateRef, []);
72
72
  * compiled(100n); // 100n
73
73
  * ```
74
74
  *
@@ -92,7 +92,7 @@ export declare class RefExpr<T extends any> extends Expr<RefType<T>> {
92
92
  * $(counter.merge(delta, ($, current, newVal) => current.add(newVal)));
93
93
  * $.return(counter.get());
94
94
  * });
95
- * const compiled = East.compile(incrementRef.toIR(), []);
95
+ * const compiled = East.compile(incrementRef, []);
96
96
  * compiled(5n); // 15n
97
97
  * ```
98
98
  *
@@ -15,7 +15,7 @@ import { AstSymbol, Expr, FactorySymbol, TypeSymbol } from "./expr.js";
15
15
  * const counter = $.let(East.value(ref(42n)));
16
16
  * $.return(counter.get());
17
17
  * });
18
- * const compiled = East.compile(getRefValue.toIR(), []);
18
+ * const compiled = East.compile(getRefValue, []);
19
19
  * compiled(); // 42n
20
20
  * ```
21
21
  *
@@ -27,7 +27,7 @@ import { AstSymbol, Expr, FactorySymbol, TypeSymbol } from "./expr.js";
27
27
  * $(counter.update(newValue));
28
28
  * $.return(counter.get());
29
29
  * });
30
- * const compiled = East.compile(updateRef.toIR(), []);
30
+ * const compiled = East.compile(updateRef, []);
31
31
  * compiled(100n); // 100n
32
32
  * ```
33
33
  */
@@ -48,7 +48,7 @@ export class RefExpr extends Expr {
48
48
  * const counter = $.let(East.value(ref(42n)));
49
49
  * $.return(counter.get());
50
50
  * });
51
- * const compiled = East.compile(getRefValue.toIR(), []);
51
+ * const compiled = East.compile(getRefValue, []);
52
52
  * compiled(); // 42n
53
53
  * ```
54
54
  */
@@ -75,7 +75,7 @@ export class RefExpr extends Expr {
75
75
  * $(counter.update(newValue));
76
76
  * $.return(counter.get());
77
77
  * });
78
- * const compiled = East.compile(updateRef.toIR(), []);
78
+ * const compiled = East.compile(updateRef, []);
79
79
  * compiled(100n); // 100n
80
80
  * ```
81
81
  *
@@ -108,7 +108,7 @@ export class RefExpr extends Expr {
108
108
  * $(counter.merge(delta, ($, current, newVal) => current.add(newVal)));
109
109
  * $.return(counter.get());
110
110
  * });
111
- * const compiled = East.compile(incrementRef.toIR(), []);
111
+ * const compiled = East.compile(incrementRef, []);
112
112
  * compiled(5n); // 15n
113
113
  * ```
114
114
  *