@dallaylaen/ski-interpreter 2.3.1 → 2.3.3
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.
- package/CHANGELOG.md +18 -0
- package/lib/ski-interpreter.cjs.js +28 -0
- package/lib/ski-interpreter.cjs.js.map +2 -2
- package/lib/ski-interpreter.esm.js +28 -0
- package/lib/ski-interpreter.esm.js.map +2 -2
- package/lib/ski-interpreter.min.js +3 -3
- package/lib/ski-interpreter.min.js.map +3 -3
- package/lib/ski-quest.min.js +2 -2
- package/lib/ski-quest.min.js.map +3 -3
- package/package.json +1 -1
- package/types/src/expr.d.ts +25 -0
|
@@ -292,6 +292,34 @@ var require_expr = __commonJS({
|
|
|
292
292
|
const [value, _] = unwrap(this._fold(initial, combine));
|
|
293
293
|
return value ?? initial;
|
|
294
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* @experimental
|
|
297
|
+
* @desc Fold an application tree bottom to top.
|
|
298
|
+
* For each subtree, the function is given the term in the root position and
|
|
299
|
+
* a list of the results of folding its arguments.
|
|
300
|
+
*
|
|
301
|
+
* E.g. fold('x y (z t)', f) results in f(x, [f(y, []), f(z, [f(t, [])])])
|
|
302
|
+
*
|
|
303
|
+
* @example expr.foldBottomUp((head, tail) => {
|
|
304
|
+
* if (head.arity && head.arity <= tail.length) {
|
|
305
|
+
* return '(<span class="redex">'
|
|
306
|
+
* + head + ' '
|
|
307
|
+
* + tail.slice(0, head.arity).join(' ')
|
|
308
|
+
* + '</span>'
|
|
309
|
+
* + tail.slice(head.arity).join(' ')
|
|
310
|
+
* + ')';
|
|
311
|
+
* } else {
|
|
312
|
+
* return '(' + head + ' ' + tail.join(' ') + ')';
|
|
313
|
+
* }
|
|
314
|
+
* });
|
|
315
|
+
* @template T
|
|
316
|
+
* @param {(head: Expr, tail: T[]) => T} fun
|
|
317
|
+
* @return {T}
|
|
318
|
+
*/
|
|
319
|
+
foldBottomUp(fun) {
|
|
320
|
+
const [head, ...tail] = this.unroll();
|
|
321
|
+
return fun(head, tail.map((e) => e.foldBottomUp(fun)));
|
|
322
|
+
}
|
|
295
323
|
/**
|
|
296
324
|
* @template T
|
|
297
325
|
* @param {T} initial
|