hclang 0.24.0 → 0.24.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.
@@ -1330,8 +1330,21 @@ export const HC_SOURCES = new Map([
1330
1330
  "; [(3 U) = ((U U) U), ((3 U).children .0) === Z, ((3 U).children .2) === U, U = (Figure [Z])]",
1331
1331
  "# [<>, <>, <>, <>]",
1332
1332
  "```",
1333
+ "So `n U` is not the tally n. Repetition starts from nil, so its first step",
1334
+ "answers U itself, whose child is `Z`, and `3 U` holds `Z` and two units. A tally",
1335
+ "starts from zero instead: join n units onto `Z`, or construct them. Repetition",
1336
+ "keeps nil as its start, because a declared zero would be a new protocol point",
1337
+ "with this one use (#415)",
1338
+ "```",
1339
+ "; [((3 U).size()).children.#, (((3 [U]) | Z).size()).children.#, ((3 [U]) | Z) = (Figure (3 [U]))]",
1340
+ "# [2, 3, <>]",
1341
+ "```",
1333
1342
  "A join copies its receiver once and appends in place after that, so it is",
1334
- "quick, and the receiver and every child keep their identity",
1343
+ "quick, and the receiver and every child keep their identity. Each step still",
1344
+ "copies the children it has so far, because a collect through a name always lands",
1345
+ "on a fresh array (#386). That keeps a join quadratic in pointer copies, about",
1346
+ "0.9 s for 4,096 units, and the observers never join: they construct from a",
1347
+ "stream in one step (#415)",
1335
1348
  "```",
1336
1349
  "; .joined ((512 [U]) | Z);",
1337
1350
  "; [joined.children.#, Z = (Figure []), (joined.children .511) === U]",
@@ -1418,6 +1431,21 @@ export const HC_SOURCES = new Map([
1418
1431
  "; [(U.mul Z) = Z, ((Figure [Z]).size()) = (Figure [U])]",
1419
1432
  "# [<>, <>]",
1420
1433
  "```",
1434
+ "That exception is the price of a unit defined by form, and the module pays it",
1435
+ "on purpose (#415). Construction of two or more Figures adds, and construction",
1436
+ "of one wraps: wrapping keeps the Size of anything that is not shaped like zero,",
1437
+ "and wrapping zero makes a cell. Counting cells by identity instead, as `_^ === U`,",
1438
+ "would remove both guards, but a separately built `Figure [Figure []]`, equal to",
1439
+ "`U` in every child, would then have no cells, so Size would no longer be a",
1440
+ "function of form. Tried against the 55 claims this file held at v0.24.0,",
1441
+ "identity cells failed only the three that say a form-equal unit is a cell",
1442
+ "```",
1443
+ "; [(Figure [row2]).size_equivalent row2, (Figure [Z]).size_equivalent U, (Figure [Z]).size_equivalent Z] = [U, U, Z]",
1444
+ "# <>",
1445
+ "; .U2 (Figure [Figure []]);",
1446
+ "; [U2 = U, U2 === U, (U2.size()) = (U.size())]",
1447
+ "# [<>, (), <>]",
1448
+ "```",
1421
1449
  "A non-square product is two occurrences of one three-cell row, and both",
1422
1450
  "positions are the same `row3`. Manyness sees two rows, while Size counts six",
1423
1451
  "```",
@@ -3355,6 +3383,13 @@ export const HC_SOURCES = new Map([
3355
3383
  "; mag (.x 1; .y 2;)",
3356
3384
  "# 5",
3357
3385
  "```",
3386
+ "Each call evaluates the body afresh, so a group the body builds holds that",
3387
+ "call's values, as an array does (#404):",
3388
+ "```",
3389
+ "; .pair {(.a _; .b (a + 1);)};",
3390
+ "; [pair 1, pair 2]",
3391
+ "# [(.a 1; .b 2;), (.a 2; .b 3;)]",
3392
+ "```",
3358
3393
  "You can reach past the argument to the enclosing lexical scope (one level above)",
3359
3394
  "using the `_^` identifier. It is not a `super` reference: it names the scope the",
3360
3395
  "closure was written in, not a declared parent, and each caret is one more",
@@ -3380,6 +3415,18 @@ export const HC_SOURCES = new Map([
3380
3415
  "; mag []",
3381
3416
  "# 25",
3382
3417
  "```",
3418
+ "A closure keeps the scope it was created in wherever it is later read, so one",
3419
+ "closure handed to another as an argument still finds its own names (#424). A",
3420
+ "closure factory therefore nests exactly as often as it is called",
3421
+ "```",
3422
+ "; .Mk {.lower _; {[“level”, lower _]}};",
3423
+ "; .L0 {“base”};",
3424
+ "; (Mk (Mk L0)) 7",
3425
+ "# [“level”, [“level”, “base”]]",
3426
+ "; .Ret {.lower _; {lower}};",
3427
+ "; ((Ret (Ret L0)) 0) 0",
3428
+ "# { “base” }",
3429
+ "```",
3383
3430
  "Implicit arguments are a code smell, and will generate a warning.",
3384
3431
  "However, they can be very useful when debugging or refactoring. That may seem",
3385
3432
  "dangerous, but the data protection rules (below) largely limit what the called",
@@ -9,20 +9,36 @@ export class FrameGroup extends FrameList {
9
9
  constructor(data, meta = NilContext) {
10
10
  super(data, meta);
11
11
  }
12
- scoped(input) {
13
- const scope = EvaluationScope.from(input).withLayer(this);
14
- return this.declares ? scope.withWriteTarget(this, "construction") : scope;
12
+ /**
13
+ * The scope this group's terms are evaluated in. `target` is the layer they
14
+ * read the group's properties from and, for a group written in source, the
15
+ * frame their declarations land on.
16
+ */
17
+ scoped(input, target) {
18
+ const scope = EvaluationScope.from(input).withLayer(target);
19
+ return this.declares
20
+ ? scope.withWriteTarget(target, "construction")
21
+ : scope;
15
22
  }
23
+ /**
24
+ * A group of one answers its term, carrying the group's properties. They
25
+ * are collected on a fresh copy, so one evaluation's declarations reach its
26
+ * own answer and never a later evaluation of the same group (#404).
27
+ */
16
28
  eval_one(input = []) {
17
- const scope = this.scoped(input);
18
- const expr = this.data[0];
19
- const result = expr.in(scope);
20
- const symbols = this.meta_pairs();
21
- symbols.forEach(([key, value]) => {
29
+ const target = this.copy();
30
+ const result = this.data[0].in(this.scoped(input, target));
31
+ target.meta_pairs().forEach(([key, value]) => {
22
32
  result.set(key, value);
23
33
  });
24
34
  return result;
25
35
  }
36
+ /**
37
+ * A parsed group is source, and a closure evaluates the same one on every
38
+ * call, so the value is always a fresh group and this one is never written.
39
+ * Evaluating in place replaced its terms with the first call's answers,
40
+ * which every later call then answered again (#404).
41
+ */
26
42
  in(input = []) {
27
43
  switch (this.size()) {
28
44
  case 0: {
@@ -32,9 +48,10 @@ export class FrameGroup extends FrameList {
32
48
  return this.eval_one(input);
33
49
  }
34
50
  }
35
- const scope = this.scoped(input);
36
- this.data = this.data.map((frame) => frame.in(scope));
37
- return this;
51
+ const result = this.copy();
52
+ const scope = this.scoped(input, result);
53
+ result.data = result.data.map((frame) => frame.in(scope));
54
+ return result;
38
55
  }
39
56
  /**
40
57
  * `()` is nil, so a repetition left with no term at all answers nil:
@@ -106,7 +106,9 @@ export class FrameSymbol extends FrameAtom {
106
106
  // Every successful read gets its own lexical projection. Closures bind
107
107
  // a scoped copy, aggregates keep their exact identity behind a handle,
108
108
  // and immutable values use a plumbing copy. The shared binding is never
109
- // re-parented for the benefit of one reader.
109
+ // re-parented for the benefit of one reader, so only a projection this
110
+ // read created takes the read site as its `up`: a closure that is
111
+ // already bound answers itself and keeps the scope it was made in.
110
112
  const isCanonicalBoolean = value === Frame.nil || value === Frame.all;
111
113
  const continuation = context instanceof FrameHandle
112
114
  ? context
@@ -116,7 +118,7 @@ export class FrameSymbol extends FrameAtom {
116
118
  : value instanceof FrameArray || isCanonicalBoolean
117
119
  ? value
118
120
  : value.copy();
119
- if (!(resolved instanceof FrameArray) && !isCanonicalBoolean) {
121
+ if (resolved !== value) {
120
122
  resolved.up = continuation;
121
123
  }
122
124
  // Built-in control flow receives the exact active capability only for
@@ -1 +1 @@
1
- export const VERSION = "0.24.0";
1
+ export const VERSION = "0.24.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",