hclang 0.24.1 → 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.
@@ -3383,6 +3383,13 @@ export const HC_SOURCES = new Map([
3383
3383
  "; mag (.x 1; .y 2;)",
3384
3384
  "# 5",
3385
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
+ "```",
3386
3393
  "You can reach past the argument to the enclosing lexical scope (one level above)",
3387
3394
  "using the `_^` identifier. It is not a `super` reference: it names the scope the",
3388
3395
  "closure was written in, not a declared parent, and each caret is one more",
@@ -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:
@@ -1 +1 @@
1
- export const VERSION = "0.24.1";
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.1",
3
+ "version": "0.24.2",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",