hclang 0.23.1 → 0.23.2

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.
@@ -496,6 +496,20 @@ export const HC_SOURCES = new Map([
496
496
  "; [((row xs) .2) === xs, (row xs) === row]",
497
497
  "# [<>, ()]",
498
498
  "```",
499
+ "An argument applies like a name, too (#419). A value an operation is handed,",
500
+ "an element a map gives its block or the operand of a repetition, is read-only:",
501
+ "applying it collects onto a copy, and its declared `apply_` answers a",
502
+ "functional update. Only what the operation created, a fresh literal or a",
503
+ "reduce's own accumulator, is written in place",
504
+ "```",
505
+ "; .nest [[1], [2]];",
506
+ "; [nest & {_ 9}, nest]",
507
+ "# [[[1, 9], [2, 9]], [[1], [2]]]",
508
+ "; .Acc {[.n _; .apply_ {@n (_^.n + 1);}]};",
509
+ "; .acc (Acc 0);",
510
+ "; [(3 acc).n, acc.n]",
511
+ "# [2, 0]",
512
+ "```",
499
513
  "Concatenation therefore needs no operator of its own: reduce one aggregate into",
500
514
  "another, named or computed",
501
515
  "```",
@@ -1159,11 +1173,13 @@ export const HC_SOURCES = new Map([
1159
1173
  "```;",
1160
1174
  " .children (_ | []);",
1161
1175
  "```",
1162
- "**Application**, `x y` (#375): a new Figure with x's children followed by y.",
1163
- "It leaves x unchanged and forgets nothing, so `ys | x` joins two Figures and",
1164
- "`cs | (Figure [])` constructs one out of a stream",
1176
+ "**Application**, `x y` (#375): x's children followed by y. It is a mutating",
1177
+ "method, `apply_`, so through a name, `x y` is a functional update: it answers a",
1178
+ "new Figure and leaves x unchanged. A reduce writes only the Figure its own",
1179
+ "first step answered, so `ys | x` joins two Figures, copying x once, and",
1180
+ "`cs | (Figure [])` constructs one out of a stream. It forgets nothing",
1165
1181
  "```;",
1166
- " .apply {Figure ((_^.children | []) _)};",
1182
+ " .apply_ {@children (_^.children _);};",
1167
1183
  "```",
1168
1184
  "**Manyness**, `x.many()`: a tally with one mark `B` per immediate child. It",
1169
1185
  "keeps how many children there are and forgets what they are, everything below",
@@ -1285,9 +1301,18 @@ export const HC_SOURCES = new Map([
1285
1301
  "```",
1286
1302
  "Repetition applies a Figure rather than concatenating, because a Figure",
1287
1303
  "declares its application: `3 U` is `(U U) U`, and each child it appends is `U`",
1288
- "itself",
1304
+ "itself. U is the operand, never the receiver written",
1305
+ "```",
1306
+ "; [(3 U) = ((U U) U), ((3 U).children .0) === Z, ((3 U).children .2) === U, U = (Figure [Z])]",
1307
+ "# [<>, <>, <>, <>]",
1308
+ "```",
1309
+ "A join copies its receiver once and appends in place after that, so it is",
1310
+ "quick, and the receiver and every child keep their identity",
1289
1311
  "```",
1290
- "; [(3 U) = ((U U) U), ((3 U).children .0) === Z, ((3 U).children .2) === U]",
1312
+ "; .joined ((512 [U]) | Z);",
1313
+ "; [joined.children.#, Z = (Figure []), (joined.children .511) === U]",
1314
+ "# [512, <>, <>]",
1315
+ "; [(E.children & {_ A}) = [Figure [A], Figure [Z, A]], A = (Figure []), B = (Figure [A])]",
1291
1316
  "# [<>, <>, <>]",
1292
1317
  "```",
1293
1318
  "## Manyness and Size",
@@ -365,6 +365,16 @@ export class EvaluationScope {
365
365
  }
366
366
  return scope?.argument;
367
367
  }
368
+ /**
369
+ * The argument `_`, `__`, ... as source reads it: an aggregate the call was
370
+ * handed raw is read through an immutable handle, as a name would read it,
371
+ * so applying it collects onto a copy and its mutating methods answer
372
+ * functional updates. An argument is never the call's to write (#419). A
373
+ * handle the caller passed, mutable or not, is kept as it is.
374
+ */
375
+ argumentRead(level) {
376
+ return this.argumentAt(level)?.readOnly();
377
+ }
368
378
  /** Resolves `.`, `..`, ... through exact enclosing call parameters. */
369
379
  parameterAt(level) {
370
380
  if (level <= 1)
@@ -38,7 +38,7 @@ export class FrameArg extends FrameSymbol {
38
38
  in(input = []) {
39
39
  const scope = EvaluationScope.from(input);
40
40
  const level = this.data.length;
41
- const target = scope.argumentAt(level);
41
+ const target = scope.argumentRead(level);
42
42
  if (target)
43
43
  return target;
44
44
  // Outside a closure, an unresolved level remains an argument expression at
@@ -5,6 +5,7 @@ import { Frame } from "./frame.js";
5
5
  import { BoundMethod } from "./bound-method.js";
6
6
  import { methodEffect } from "./effect-marker.js";
7
7
  import { FrameExpr } from "./frame-expr.js";
8
+ import { FrameHandle } from "./frame-handle.js";
8
9
  import { FrameList } from "./frame-list.js";
9
10
  import { FrameNote } from "./frame-note.js";
10
11
  import { NilContext } from "./context.js";
@@ -61,6 +62,13 @@ export class FrameArray extends FrameList {
61
62
  ownsIdentity() {
62
63
  return true;
63
64
  }
65
+ /**
66
+ * An immutable handle on this aggregate, as a name reads it: applying it
67
+ * collects onto a copy and its mutating methods answer functional updates.
68
+ */
69
+ readOnly() {
70
+ return new FrameHandle(this, false);
71
+ }
64
72
  /**
65
73
  * `=` compares the complete view, the same one `&&` iterates: visible
66
74
  * properties in declaration order, then elements by index, each by `=`.
@@ -98,6 +98,10 @@ export class FrameHandle extends Frame {
98
98
  this.target = copy;
99
99
  return copy;
100
100
  }
101
+ /** A handle already says whether its reader may write; keep it as it is. */
102
+ readOnly() {
103
+ return this;
104
+ }
101
105
  /** A handle is transparent to equality: it compares as its target. */
102
106
  referent() {
103
107
  return this.target.referent();
@@ -192,9 +192,14 @@ export class FrameInt extends FrameNumeric {
192
192
  REPETITION_TEXT_LIMIT) {
193
193
  return Frame.error(`$!.repetition-size ${REPETITION_TEXT_LIMIT}`);
194
194
  }
195
+ // The operand arrives unwrapped, and applying to nil answers it as it is.
196
+ // Read it as a name would, so a later step that writes, such as a declared
197
+ // `apply_`, updates a copy rather than the operand itself (#419).
198
+ const operand = argument.readOnly();
195
199
  let result = Frame.nil;
196
200
  for (let index = 0; index < count; index += 1) {
197
- result = result.apply(argument, parameter);
201
+ const next = result.apply(operand, parameter);
202
+ result = next === operand.referent() ? operand : next;
198
203
  }
199
204
  return result;
200
205
  }
@@ -253,6 +253,14 @@ export class Frame extends MetaFrame {
253
253
  ownsIdentity() {
254
254
  return false;
255
255
  }
256
+ /**
257
+ * This frame as a value its reader may not write (#419). Only an aggregate
258
+ * owns identity a write can land on, so every other frame is its own
259
+ * read-only view; `FrameArray` answers an immutable handle on itself.
260
+ */
261
+ readOnly() {
262
+ return this;
263
+ }
256
264
  /** Compare only this frame's data plane, excluding metadata. */
257
265
  dataEquals(other) {
258
266
  return this.dataString() === other.dataString() ? Frame.all : Frame.nil;
@@ -1 +1 @@
1
- export const VERSION = "0.23.1";
1
+ export const VERSION = "0.23.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.23.1",
3
+ "version": "0.23.2",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",