@dallaylaen/ski-interpreter 2.5.2 → 2.6.1

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.
@@ -14810,8 +14810,8 @@ var Church = class _Church extends Expr {
14810
14810
  return nargs >= 2 ? options.redex[0] + this.n + options.redex[1] : this.n + "";
14811
14811
  }
14812
14812
  };
14813
- function waitn(expr, n) {
14814
- return (arg) => n <= 1 ? expr.apply(arg) : waitn(expr.apply(arg), n - 1);
14813
+ function waitn(n) {
14814
+ return n <= 1 ? (e) => (arg) => e.apply(arg) : (e) => (arg) => waitn(n - 1)(e.apply(arg));
14815
14815
  }
14816
14816
  var Alias = class extends Named {
14817
14817
  constructor(name, impl, options = {}) {
@@ -14820,17 +14820,28 @@ var Alias = class extends Named {
14820
14820
  throw new Error("Attempt to create an alias for a non-expression: " + impl);
14821
14821
  this.impl = impl;
14822
14822
  this._setup(options);
14823
- this.terminal = options.terminal ?? this.props?.proper;
14824
- this.invoke = waitn(impl, this.arity ?? 0);
14823
+ this.invoke = waitn(options.inline ? 0 : this.arity ?? 0)(impl);
14825
14824
  this.size = impl.size;
14826
- if (options.outdated)
14827
- this.outdated = true;
14825
+ if (options.inline)
14826
+ this.inline = true;
14827
+ }
14828
+ /**
14829
+ * @desc Make the alias inline, i.e. replace it with its implementation everywhere.
14830
+ *
14831
+ * Replaces the old `outdated` attribute.
14832
+ * Used by the parser when a term definition is removed or updated.
14833
+ *
14834
+ * May change in future versions, use with caution.
14835
+ *
14836
+ * @experimental
14837
+ * @returns {this}
14838
+ */
14839
+ makeInline() {
14840
+ this.invoke = waitn(0)(this.impl);
14841
+ this.inline = true;
14842
+ return this;
14828
14843
  }
14829
14844
  /**
14830
- * @property {boolean} [outdated] - whether the alias is outdated
14831
- * and should be replaced with its definition when encountered.
14832
- * @property {boolean} [terminal] - whether the alias should behave like a standalone term
14833
- * // TODO better name?
14834
14845
  * @property {boolean} [proper] - whether the alias is a proper combinator (i.e. contains no free variables or constants)
14835
14846
  * @property {number} [arity] - the number of arguments the alias waits for before expanding
14836
14847
  * @property {Expr} [canonical] - equivalent lambda term.
@@ -14873,11 +14884,11 @@ var Alias = class extends Named {
14873
14884
  return other.diff(this.impl, !swap);
14874
14885
  }
14875
14886
  _braced(first) {
14876
- return this.outdated ? this.impl._braced(first) : false;
14887
+ return this.inline ? this.impl._braced(first) : false;
14877
14888
  }
14878
14889
  formatImpl(options, nargs) {
14879
- const outdated = options.inventory ? options.inventory[this.name] !== this : this.outdated;
14880
- return outdated ? this.impl.formatImpl(options, nargs) : super.formatImpl(options, nargs);
14890
+ const inline = options.inventory ? options.inventory[this.name] !== this : this.inline;
14891
+ return inline ? this.impl.formatImpl(options, nargs) : super.formatImpl(options, nargs);
14881
14892
  }
14882
14893
  diag(indent = "") {
14883
14894
  return `${indent}Alias (${this.name}): \\
@@ -15089,8 +15100,9 @@ var Parser = class {
15089
15100
  const named = this._named(term, impl);
15090
15101
  const opts = typeof options === "string" ? { note: options, canonize: false } : options ?? {};
15091
15102
  named._setup({ canonize: this.annotate, ...opts });
15092
- if (this.known[named.name])
15093
- this.known[named.name].outdated = true;
15103
+ const old = this.known[named.name];
15104
+ if (old instanceof Alias)
15105
+ old.makeInline();
15094
15106
  this.known[named.name] = named;
15095
15107
  this.allow.add(named.name);
15096
15108
  return this;
@@ -15190,7 +15202,9 @@ var Parser = class {
15190
15202
  * @return {SKI}
15191
15203
  */
15192
15204
  remove(name) {
15193
- this.known[name].outdated = true;
15205
+ const old = this.known[name];
15206
+ if (old instanceof Alias)
15207
+ old.makeInline();
15194
15208
  delete this.known[name];
15195
15209
  this.allow.delete(name);
15196
15210
  return this;
@@ -15275,7 +15289,7 @@ var Parser = class {
15275
15289
  let expr = new Empty();
15276
15290
  for (const item of lines) {
15277
15291
  if (expr instanceof Alias)
15278
- expr.outdated = true;
15292
+ expr.makeInline();
15279
15293
  const def = item.match(/^([A-Z]|[a-z][a-z_0-9]*)\s*=(.*)$/s);
15280
15294
  if (def && def[2] === "")
15281
15295
  expr = new FreeVar(def[1], options.scope ?? FreeVar.global);
@@ -15289,7 +15303,7 @@ var Parser = class {
15289
15303
  }
15290
15304
  if (this.addContext) {
15291
15305
  if (expr instanceof Named)
15292
- expr = new Alias(expr.name, expr, { outdated: true });
15306
+ expr = new Alias(expr.name, expr, { inline: true });
15293
15307
  expr.context = {
15294
15308
  env: { ...this.getTerms(), ...jar },
15295
15309
  // also contains pre-parsed terms
@@ -15397,7 +15411,7 @@ var Quest = class {
15397
15411
  for (const term of env ?? []) {
15398
15412
  const expr = this.engineFull.parse(term, { env: jar, scope: this });
15399
15413
  if (expr instanceof Alias)
15400
- this.env[expr.name] = new Alias(expr.name, expr.impl, { terminal: true, canonize: false });
15414
+ this.env[expr.name] = new Alias(expr.name, expr.impl, { canonize: false });
15401
15415
  else if (expr instanceof FreeVar)
15402
15416
  this.env[expr.name] = expr;
15403
15417
  else
@@ -15486,7 +15500,7 @@ var Quest = class {
15486
15500
  if (e instanceof Named && arsenal[e.name] === e)
15487
15501
  return control.prune(a + 1);
15488
15502
  });
15489
- const expr = impl instanceof FreeVar ? impl : new Alias(spec.fancy ?? spec.name, impl, { terminal: true, canonize: false });
15503
+ const expr = impl instanceof FreeVar ? impl : new Alias(spec.fancy ?? spec.name, impl, { canonize: false });
15490
15504
  jar[spec.name] = expr;
15491
15505
  prepared.push(expr);
15492
15506
  }
@@ -15959,4 +15973,4 @@ if (typeof window !== "undefined")
15959
15973
  export {
15960
15974
  SKI
15961
15975
  };
15962
- //# sourceMappingURL=ski-interpreter.esm.js.map
15976
+ //# sourceMappingURL=ski-interpreter.mjs.map