@dallaylaen/ski-interpreter 2.3.2 → 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 CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.3.3] - 2026-03-01
9
+
10
+ ### Changed
11
+
12
+ - `SKI.extras.foldr` is now removed in favor of
13
+ `Expr.foldBottomUp<T>(fun: (expr: Expr, args: T[]) => T): T`
14
+ with the same semantics but more descriptive name
15
+ and simpler signature.
16
+ _Was experimental (and still is), so not considered a breaking change._
17
+
8
18
  ## [2.3.2] - 2026-03-01
9
19
 
10
20
  ### Added
@@ -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
@@ -2220,11 +2248,7 @@ var require_extras = __commonJS({
2220
2248
  return s.format({ inventory: res.env });
2221
2249
  }).join("; ");
2222
2250
  }
2223
- function foldr(expr, fun) {
2224
- const [head, ...tail] = expr.unroll();
2225
- return fun(head, tail.map((e) => foldr(e, fun)));
2226
- }
2227
- module2.exports = { search, deepFormat, declare, foldr };
2251
+ module2.exports = { search, deepFormat, declare };
2228
2252
  }
2229
2253
  });
2230
2254