hclang 0.47.0 → 0.49.0

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.
@@ -1,117 +1,103 @@
1
1
  /**
2
- * The Denum class, loaded from HC for the ranked hash.
2
+ * The Denum class, loaded from HC for the fourth hash.
3
3
  *
4
- * `x.#n` answers a Denum, and the only public constructor is the HC class
5
- * `Denum` in `hc/denum.hc` (occurrence/figure 007.32, 007.36). The CD algebra
6
- * is a view derived by `d.cd ()`, not a second constructor. The frames package
7
- * derives the state natively but cannot run HC, so this module installs what
8
- * it calls (`installDenumConstructors`), exactly as `demi-prologue.ts` does for
9
- * `.####`. The `Denum` constructor builds every answer; the internal view
10
- * derivation `view-of` is installed only so a view source can be recognized
11
- * and refused. It is not a constructor of retained state and is never
12
- * exported.
4
+ * `.####` answers a Denum, and a Denum is an HC class, `Denum` in `hc/denum.hc`,
5
+ * not a native one (occurrence/figure 011.20). The frames package derives the
6
+ * Count and loads natively but cannot run HC, so this module installs the
7
+ * constructor it calls (`installDenumConstructor`).
13
8
  *
14
9
  * The class is read from the compiled-in bundle, not through a resource root,
15
- * so `.#n` works in a bare `evaluate`, which has no root and imports nothing.
10
+ * so `.####` works in a bare `evaluate`, which has no root and imports nothing.
16
11
  * The file is evaluated the first time a Denum is constructed, once per
17
- * process: its example lines are dropped and the first failure fails the whole.
18
- * It runs in a namespace of its own, with no host bindings and no root, so it
19
- * can read nothing but the global operators, among them the pure
20
- * `denum-engine`, and nothing a program declares can reach it. Its outcome is
21
- * kept, failure included, so it is never evaluated twice. A Denum requested
22
- * while the file is still loading is `$!.denum-prologue-reentrant`.
12
+ * process, the way an import evaluates a testdoc: its example lines are
13
+ * dropped and the first failure fails the whole. It runs in a namespace of its
14
+ * own, with no host bindings and no root, so it can read nothing but the
15
+ * global operators, and nothing a program declares can reach it. Its outcome
16
+ * is kept, failure included, so it is never evaluated twice. A Denum requested
17
+ * while the file is still loading is `$!.denum-prologue-reentrant`, because
18
+ * the class cannot be defined by itself.
19
+ *
20
+ * What stays native is only what HC cannot say: reading `#`, `##` and `###`
21
+ * in a fixed order with their absence and error rules, and checking that the
22
+ * loads are whole. Everything a Denum does is in the HC source.
23
23
  *
24
24
  * @module
25
25
  */
26
- import { EvaluationScope, Frame, FrameArray, FrameCount, FrameExpr, installDenumConstructors, } from "../frames.js";
26
+ import { EvaluationScope, Frame, FrameArray, FrameExpr, installDenumConstructor, } from "../frames.js";
27
27
  import { HC_SOURCES } from "../bundle/hc-sources.js";
28
28
  import { evaluateSourceText } from "./resource-import.js";
29
29
  /** The bundled file that defines the class. */
30
30
  export const DENUM_SOURCE = "hc/denum.hc";
31
- /** The name the file declares its one public constructor under. */
31
+ /** The name the file declares the constructor under. */
32
32
  export const DENUM_CLASS = "Denum";
33
- /** The internal view derivation: `view-of d` is `d.cd ()`. Not a constructor. */
34
- export const VIEW_FACTORY = "view-of";
35
33
  let loaded;
36
34
  let loading = false;
37
- const failed = (frame) => frame.isFailedResult() || frame.observationError() !== undefined;
38
35
  /**
39
- * Evaluates class source in a namespace of its own, answering its `Denum`
40
- * constructor and `view-of` derivation or the failure. Uncached: `denumClasses` keeps the one
41
- * result the process uses.
36
+ * Evaluates class source in a namespace of its own, with no host bindings and
37
+ * no root, answering its `Denum` or the failure. Uncached: `denumClass` keeps
38
+ * the one result the process uses.
42
39
  *
43
40
  * @param source The source text, or undefined when the bundle lacks it.
44
- * @returns The `Denum` constructor and the view derivation, or an error.
41
+ * @returns The constructor, or an error.
45
42
  */
46
- export function loadDenumClasses(source) {
43
+ export function loadDenumClass(source) {
47
44
  if (source === undefined) {
48
45
  return Frame.error(`$!.denum-prologue-missing ${DENUM_SOURCE}`);
49
46
  }
50
47
  const namespace = new FrameArray([]);
51
48
  const result = evaluateSourceText(source, EvaluationScope.root(namespace));
52
- if (failed(result))
49
+ if (result.isFailedResult() || result.observationError())
53
50
  return result;
54
- const denum = namespace.getOwn(DENUM_CLASS);
55
- if (denum.is.missing) {
56
- return Frame.error(`$!.denum-prologue-missing ${DENUM_CLASS}`);
57
- }
58
- const view = namespace.getOwn(VIEW_FACTORY);
59
- if (view.is.missing) {
60
- return Frame.error(`$!.denum-prologue-missing ${VIEW_FACTORY}`);
61
- }
62
- return { denum, view };
51
+ const constructor = namespace.getOwn(DENUM_CLASS);
52
+ return constructor.is.missing
53
+ ? Frame.error(`$!.denum-prologue-missing ${DENUM_CLASS}`)
54
+ : constructor;
63
55
  }
64
56
  /**
65
- * The `Denum` constructor and `view-of` closures, evaluated from the bundle on
66
- * first use.
57
+ * The `Denum` constructor closure, evaluated from the bundle on first use.
67
58
  *
68
- * @returns The closures, or the error that loading them answered.
59
+ * @returns The constructor, or the error that loading it answered.
69
60
  */
70
- export function denumClasses() {
61
+ export function denumClass() {
71
62
  if (loaded)
72
63
  return loaded;
73
64
  if (loading)
74
65
  return Frame.error("$!.denum-prologue-reentrant");
75
66
  loading = true;
76
67
  try {
77
- loaded = loadDenumClasses(HC_SOURCES.get(DENUM_SOURCE));
68
+ loaded = loadDenumClass(HC_SOURCES.get(DENUM_SOURCE));
78
69
  }
79
70
  finally {
80
71
  loading = false;
81
72
  }
82
73
  return loaded;
83
74
  }
84
- const stateArgument = (state) => new FrameArray([
85
- new FrameCount(state.count),
86
- new FrameArray(state.loads.map((load) => new FrameCount(load))),
87
- ]);
88
75
  /**
89
- * Constructs a Denum with the HC class: `Denum [count, loads]`.
76
+ * Constructs a Denum of any arity with the HC class: `Denum [count, loads]`.
77
+ * Two loads give the binary Denum, the same instance `Denum [count, left,
78
+ * right]` builds; any other nonzero number gives the channel Denum (007.27).
90
79
  *
91
- * @param state The Count and loads, already admissible.
80
+ * @param count The full application Count.
81
+ * @param loads The ordered channel loads.
92
82
  * @returns The new instance, or the class's failure.
93
83
  */
94
- export function constructDenum(state) {
95
- const classes = denumClasses();
96
- if (classes instanceof Frame)
97
- return classes;
98
- return FrameExpr.answeredValue(classes.denum.call(stateArgument(state)))
99
- .referent();
84
+ export function constructDenumLoads(count, loads) {
85
+ const constructor = denumClass();
86
+ if (constructor.isFailedResult() || constructor.observationError()) {
87
+ return constructor;
88
+ }
89
+ const state = new FrameArray([count, new FrameArray([...loads])]);
90
+ return FrameExpr.answeredValue(constructor.call(state)).referent();
100
91
  }
101
92
  /**
102
- * Derives the CD view of the Denum the state builds, as `d.cd ()` does. Only
103
- * the ranked hash's recognition of a view source uses it.
93
+ * Constructs a binary Denum with the HC class: `Denum [count, left, right]`.
104
94
  *
105
- * @param state The Count and loads, already admissible.
106
- * @returns The view instance, or the class's failure.
95
+ * @param count The full application Count; the Denum derives its phase from it.
96
+ * @param left The left load.
97
+ * @param right The right load.
98
+ * @returns The new instance, or the class's failure.
107
99
  */
108
- function deriveView(state) {
109
- const classes = denumClasses();
110
- if (classes instanceof Frame)
111
- return classes;
112
- const source = constructDenum(state);
113
- if (source.isFailedResult() || source.observationError())
114
- return source;
115
- return FrameExpr.answeredValue(classes.view.call(source)).referent();
100
+ export function constructDenum(count, left, right) {
101
+ return constructDenumLoads(count, [left, right]);
116
102
  }
117
- installDenumConstructors({ denum: constructDenum, view: deriveView });
103
+ installDenumConstructor(constructDenumLoads);
@@ -1,7 +1,5 @@
1
1
  import { Frame, FrameCount, FrameString, FrameSymbol, } from "../frames.js";
2
- // Installs the Demi class that `.####` constructs (011.20).
3
- import "./demi-prologue.js";
4
- // Installs the Denum class that the ranked hash `.#n` constructs (007.32).
2
+ // Installs the Denum class that `.####` constructs (011.20).
5
3
  import "./denum-prologue.js";
6
4
  // Installs the RotorRouter class that list division answers (007.27c).
7
5
  import "./router-prologue.js";
@@ -126,7 +126,7 @@ function evaluateResourceSourceWithChain(resource, scope, activeImports) {
126
126
  * Evaluates HC source text as an import would: example lines dropped, the first
127
127
  * failed form failing the whole, and the last answer returned. Declarations
128
128
  * land in the scope's write target. Used for source the program carries rather
129
- * than reads, such as the Demi class (`demi-prologue.ts`).
129
+ * than reads, such as the Denum class (`denum-prologue.ts`).
130
130
  *
131
131
  * @param source The source text.
132
132
  * @param scope The scope it evaluates in.
@@ -8,7 +8,7 @@
8
8
  * HC, so this module installs the constructor it calls
9
9
  * (`installDivisionCarrier`).
10
10
  *
11
- * As with the Demi class (`demi-prologue.ts`), the class is read from the
11
+ * As with the Denum class (`denum-prologue.ts`), the class is read from the
12
12
  * compiled-in bundle, evaluated once per process on first use, in a namespace
13
13
  * of its own with no host bindings and no root, and its outcome is kept,
14
14
  * failure included. A division requested while the file is still loading is
@@ -97,7 +97,7 @@ export function constructRouter(channels) {
97
97
  * The channels of an instance of the shipped class with other than two
98
98
  * channels, for `.####` (007.27); undefined for anything else.
99
99
  *
100
- * Recognition mirrors the Demi's (007.25e): the source's own stored
100
+ * Recognition mirrors the Denum's (007.25e): the source's own stored
101
101
  * `channels`, a list of arrays, must rebuild through the constructor into a
102
102
  * router `==` to the source, fields and methods included. Nothing of the
103
103
  * source runs, so a record that only spells `channels` is not a router.
@@ -3,13 +3,13 @@ import { FrameCount } from "./frame-count.js";
3
3
  import { FrameInt } from "./frame-int.js";
4
4
  let construct;
5
5
  /**
6
- * Installs what `.####` answers a present Demi with. The Demi is an HC class,
7
- * `Demi` in `hc/demi.hc`, so the frames package, which cannot run HC, takes
8
- * its constructor from the evaluator (`lib/execute/demi-prologue.ts`).
6
+ * Installs what `.####` answers a present Denum with. The Denum is an HC class,
7
+ * `Denum` in `hc/denum.hc`, so the frames package, which cannot run HC, takes
8
+ * its constructor from the evaluator (`lib/execute/denum-prologue.ts`).
9
9
  *
10
10
  * @param constructor The constructor, called once per present observation.
11
11
  */
12
- export function installDemiConstructor(constructor) {
12
+ export function installDenumConstructor(constructor) {
13
13
  construct = constructor;
14
14
  }
15
15
  let recognizeRouter;
@@ -30,7 +30,7 @@ function exactCount(frame) {
30
30
  : undefined;
31
31
  }
32
32
  /**
33
- * The stored loads of a Demi instance: its own `loads` field, a nonempty list
33
+ * The stored loads of a Denum instance: its own `loads` field, a nonempty list
34
34
  * whose elements are all exact Counts, or undefined.
35
35
  *
36
36
  * Only the instance's own field is read (`get_here`), never a declared parent
@@ -49,17 +49,17 @@ function storedLoads(source) {
49
49
  : undefined;
50
50
  }
51
51
  /**
52
- * The intrinsic Demi path (007.25e). A constructed Demi is the one Frame whose
53
- * fourth hash the three observers cannot decide: `Demi [0, 0, 0]` reads 0, 0,
52
+ * The intrinsic Denum path (007.25e). A constructed Denum is the one Frame whose
53
+ * fourth hash the three observers cannot decide: `Denum [0, 0, 0]` reads 0, 0,
54
54
  * 0, exactly as `[]` does, yet it is a present state. Rather than let any
55
55
  * class declare its own `.####`, the fourth hash recognizes an instance of the
56
56
  * shipped class itself, and nothing else.
57
57
  *
58
- * A source is a Demi exactly when it has a stored Count `count` and a stored
58
+ * A source is a Denum exactly when it has a stored Count `count` and a stored
59
59
  * nonempty list of Counts `loads`, and it is `==` (same value and same type at
60
- * every node, fields and methods included) to the Demi the shipped constructor
61
- * builds from them. A binary Demi stores `left` and `right` too, and the
62
- * comparison covers them. The answer is then that fresh reconstruction, of
60
+ * every node, fields and methods included) to the Denum the shipped constructor
61
+ * builds from them. A Denum stores nothing else (007.40), and the comparison
62
+ * covers its methods too. The answer is then that fresh reconstruction, of
63
63
  * the source's own arity, never the source
64
64
  * and never anything the source computed. No observer, method or closure of
65
65
  * the source runs, so a forged `#`, `##`, `###` or `####` cannot steer it, and
@@ -69,9 +69,17 @@ function storedLoads(source) {
69
69
  * other Frame.
70
70
  *
71
71
  * @param source The observed Frame.
72
- * @returns A fresh Demi equal to the source, or undefined.
72
+ * @returns A fresh Denum equal to the source, or undefined.
73
73
  */
74
- function intrinsicDemi(source) {
74
+ function intrinsicDenum(source) {
75
+ return recognizeDenum(source)?.denum;
76
+ }
77
+ /**
78
+ * Recognizes an instance of the shipped Denum class exactly as
79
+ * `intrinsicDenum` documents, answering its reconstruction together with the
80
+ * stored Count and loads it was rebuilt from, or undefined.
81
+ */
82
+ function recognizeDenum(source) {
75
83
  if (!construct)
76
84
  return undefined;
77
85
  const host = source.referent();
@@ -85,27 +93,79 @@ function intrinsicDemi(source) {
85
93
  if (candidate.isFailedResult() || candidate.observationError()) {
86
94
  return undefined;
87
95
  }
88
- return candidate.typeEquals(host) === Frame.all ? candidate : undefined;
96
+ return candidate.typeEquals(host) === Frame.all
97
+ ? {
98
+ denum: candidate,
99
+ count: count.data,
100
+ loads: loads.map((load) => load.data),
101
+ }
102
+ : undefined;
103
+ }
104
+ /**
105
+ * The most loads `.#%` materializes. The Count is exact and unbounded, but the
106
+ * bound Denum holds C loads, so a Count above this is refused with
107
+ * `$!.denum-binding-capacity` rather than allocated, truncated or converted.
108
+ */
109
+ export const DENUM_BINDING_CAPACITY = 65536n;
110
+ /**
111
+ * Count binding, `d.#%` (occurrence/figure 007.39a, 007.40). For a Denum
112
+ * `d = (C; [a0, …, a(A−1)])` with C > 0 it answers the new Denum
113
+ * `(C; [b0, …, b(C−1)])`, where `bj` is the sum of every `ai` with
114
+ * `i mod C = j`: fewer loads than C are copied and zero-filled, exactly C are
115
+ * kept, and more fold onto the first C by index. The Count, the total Size
116
+ * and nonnegativity are kept, the arity becomes C, and binding is idempotent.
117
+ * It is not a rank and allocates no geometry.
118
+ *
119
+ * Only a genuine Denum is bound, recognized as `.####` recognizes it, so
120
+ * nothing of the receiver runs. In order: a failed receiver is answered as it
121
+ * is; anything that is not a Denum is `$!.denum-binding-receiver`; Count zero
122
+ * is `$!.denum-binding-zero-count`, since there is no channel to bind into;
123
+ * and a Count above `DENUM_BINDING_CAPACITY` is `$!.denum-binding-capacity`.
124
+ * The receiver is never changed.
125
+ *
126
+ * @param source The observed Frame.
127
+ * @returns The bound Denum, or an error.
128
+ */
129
+ export function bindDenumCount(source) {
130
+ const failure = source.observationError();
131
+ if (failure)
132
+ return failure;
133
+ if (!construct)
134
+ return Frame.error("$!.denum-unavailable");
135
+ const state = recognizeDenum(source);
136
+ if (!state)
137
+ return Frame.error("$!.denum-binding-receiver");
138
+ if (state.count === 0n)
139
+ return Frame.error("$!.denum-binding-zero-count");
140
+ if (state.count > DENUM_BINDING_CAPACITY) {
141
+ return Frame.error("$!.denum-binding-capacity");
142
+ }
143
+ const arity = Number(state.count);
144
+ const bound = new Array(arity).fill(0n);
145
+ state.loads.forEach((load, index) => {
146
+ bound[index % arity] += load;
147
+ });
148
+ return construct(new FrameCount(state.count), bound.map((load) => new FrameCount(load)));
89
149
  }
90
150
  /**
91
151
  * The channel-router path (007.27). A router of k channels routes to channel
92
- * C mod k, which only a Demi of k loads follows; the binary Demi the observers
152
+ * C mod k, which only a Denum of k loads follows; the binary Denum the observers
93
153
  * derive follows parity, so for k other than two it would not be the router's
94
154
  * shadow. An instance of the shipped `RotorRouter` class with other than two
95
- * channels therefore answers the channel Demi of its Count and channel loads,
96
- * `Demi [C, [load0, …]]`, where a load is the summed Size of a channel's
155
+ * channels therefore answers the channel Denum of its Count and channel loads,
156
+ * `Denum [C, [load0, …]]`, where a load is the summed Size of a channel's
97
157
  * children and an empty channel's load is 0. The binary router keeps the
98
- * derived path, which already answers `Demi(C, L, R)`.
158
+ * derived path, which already answers `Denum(C, L, R)`.
99
159
  *
100
- * Its Count is the children it holds; at Count zero it has no Demi, as the
160
+ * Its Count is the children it holds; at Count zero it has no Denum, as the
101
161
  * empty binary router and the empty host have none. Each child's Size is read
102
162
  * once, and a failed Size is answered as it is.
103
163
  *
104
164
  * @param source The observed Frame.
105
- * @returns The router's channel Demi, nil, an error, or undefined when the
165
+ * @returns The router's channel Denum, nil, an error, or undefined when the
106
166
  * source is not a channel router.
107
167
  */
108
- function channelRouterDemi(source) {
168
+ function channelRouterDenum(source) {
109
169
  const channels = recognizeRouter?.(source);
110
170
  if (!channels)
111
171
  return undefined;
@@ -123,52 +183,52 @@ function channelRouterDemi(source) {
123
183
  return size;
124
184
  const load = exactCount(size);
125
185
  if (!load)
126
- return Frame.error("$!.demi-observations");
186
+ return Frame.error("$!.denum-observations");
127
187
  loads.push(new FrameCount(load.data));
128
188
  }
129
189
  if (!construct)
130
- return Frame.error("$!.demi-unavailable");
190
+ return Frame.error("$!.denum-unavailable");
131
191
  return construct(new FrameCount(count), loads);
132
192
  }
133
193
  /**
134
- * The fourth hash, `.####`. For a constructed Demi it is that Demi's own state
135
- * (`intrinsicDemi`), Count zero included. For every other Frame it is derived
194
+ * The fourth hash, `.####`. For a constructed Denum it is that Denum's own state
195
+ * (`intrinsicDenum`), Count zero included. For every other Frame it is derived
136
196
  * only from the existing observers: Count n, Size s and residual r give the
137
- * loads (s+r)/2 and (s−r)/2, and n itself is the Demi's Count, kept whole
197
+ * loads (s+r)/2 and (s−r)/2, and n itself is the Denum's Count, kept whole
138
198
  * rather than reduced to its parity (007.25c). It never folds, executes or
139
199
  * caches the source, and reads each observer at most once.
140
200
  *
141
201
  * A derived source with Count zero is nil: a host with no children has no
142
- * Demi, so `[].####` and `0.####` are nil while `(Demi [0, 0, 0]).####` is
202
+ * Denum, so `[].####` and `0.####` are nil while `(Denum [0, 0, 0]).####` is
143
203
  * present. No class can declare `.####` for itself; only the three observers
144
204
  * are declarable (`FrameArray.OBSERVATION_KEYS`).
145
205
  *
146
206
  * In order: a failure of the source or of any observer is answered as it is;
147
207
  * no Count (nil) or Count zero is nil; nil residual is nil; observations that
148
- * are not exact Counts and an integer are `$!.demi-observations`; and loads
149
- * that are negative or not whole are `$!.demi-coherence`. Only then is the
150
- * Demi constructed (011.18b–m).
208
+ * are not exact Counts and an integer are `$!.denum-observations`; and loads
209
+ * that are negative or not whole are `$!.denum-coherence`. Only then is the
210
+ * Denum constructed (011.18b–m).
151
211
  *
152
212
  * @param source The observed Frame.
153
- * @returns A Demi, nil, or an error.
213
+ * @returns A Denum, nil, or an error.
154
214
  */
155
- export function observeDemi(source) {
215
+ export function observeDenum(source) {
156
216
  const failure = source.observationError();
157
217
  if (failure)
158
218
  return failure;
159
- const intrinsic = intrinsicDemi(source);
219
+ const intrinsic = intrinsicDenum(source);
160
220
  if (intrinsic)
161
221
  return intrinsic;
162
- const routed = channelRouterDemi(source);
222
+ const routed = channelRouterDenum(source);
163
223
  if (routed)
164
224
  return routed;
165
225
  const n = source.sizeFor(Frame.kCOUNT);
166
226
  if (n.observationError())
167
227
  return n;
168
228
  if (n === Frame.nil)
169
- return Frame.nil; // no Count, no Demi (011.18k)
229
+ return Frame.nil; // no Count, no Denum (011.18k)
170
230
  if (!(n instanceof FrameCount) || typeof n.data !== "bigint" || n.data < 0n) {
171
- return Frame.error("$!.demi-count");
231
+ return Frame.error("$!.denum-count");
172
232
  }
173
233
  if (n.data === 0n)
174
234
  return Frame.nil;
@@ -182,17 +242,18 @@ export function observeDemi(source) {
182
242
  return Frame.nil;
183
243
  if (!(s instanceof FrameCount) || !(r instanceof FrameInt) ||
184
244
  typeof s.data !== "bigint" || typeof r.data !== "bigint" || s.data < 0n)
185
- return Frame.error("$!.demi-observations");
245
+ return Frame.error("$!.denum-observations");
186
246
  const sum = s.data + r.data;
187
247
  const difference = s.data - r.data;
188
248
  if (sum < 0n || difference < 0n || sum % 2n !== 0n || difference % 2n !== 0n) {
189
- return Frame.error("$!.demi-coherence");
249
+ return Frame.error("$!.denum-coherence");
190
250
  }
191
251
  if (!construct)
192
- return Frame.error("$!.demi-unavailable");
252
+ return Frame.error("$!.denum-unavailable");
193
253
  return construct(new FrameCount(n.data), [
194
254
  new FrameCount(sum / 2n),
195
255
  new FrameCount(difference / 2n),
196
256
  ]);
197
257
  }
198
- Frame.demi = observeDemi;
258
+ Frame.denum = observeDenum;
259
+ Frame.bindCount = bindDenumCount;
@@ -373,7 +373,7 @@ export class FrameArray extends FrameList {
373
373
  /** A declared Count, Size or residual first; the list's own rule otherwise. */
374
374
  sizeFor(key) {
375
375
  const failure = this.observationError();
376
- if (failure && Frame.isSizeOperator(key))
376
+ if (failure && Frame.SIZE_OPERATORS.includes(key))
377
377
  return failure;
378
378
  return this.declaredObservation(key) ?? super.sizeFor(key);
379
379
  }
@@ -537,8 +537,8 @@ Object.defineProperty(FrameArray, "TEXT_KEY", {
537
537
  * Count, Size and residual. `.####` is not among them, because it is derived
538
538
  * from these three, so a class that declares them gets it for free. No
539
539
  * class declares `.####`: a method under that name is an ordinary property
540
- * the fourth hash never runs. The one Demi these cannot derive, a constructed
541
- * zero-Count Demi, is recognized intrinsically (`fourth-hash.ts`).
540
+ * the fourth hash never runs. The one Denum these cannot derive, a constructed
541
+ * zero-Count Denum, is recognized intrinsically (`fourth-hash.ts`).
542
542
  */
543
543
  Object.defineProperty(FrameArray, "OBSERVATION_KEYS", {
544
544
  enumerable: true,
@@ -177,7 +177,7 @@ export class FrameExpr extends FrameList {
177
177
  continue;
178
178
  }
179
179
  if (index === 0 && value.isSymbol() && value.is.address &&
180
- Frame.isSizeOperator(value.spelling())) {
180
+ Frame.SIZE_OPERATORS.includes(value.spelling())) {
181
181
  sum = value;
182
182
  continue;
183
183
  }
@@ -185,7 +185,7 @@ export class FrameExpr extends FrameList {
185
185
  // is not a receiver, so a leading .## remains an address (#411).
186
186
  if (index > 0 && sum.is.void && value.isSymbol() &&
187
187
  value.is.address &&
188
- Frame.isSizeOperator(value.spelling())) {
188
+ Frame.SIZE_OPERATORS.includes(value.spelling())) {
189
189
  sum = value.called_by(sum);
190
190
  continue;
191
191
  }
@@ -553,7 +553,7 @@ export class FrameScoped extends Frame {
553
553
  /** Sizes as its term does, `.#`, `.##` and `.###`; anything else is applied. */
554
554
  call(argument, parameter = Frame.nil) {
555
555
  if (argument.isSymbol() && argument.is.address === true &&
556
- Frame.isSizeOperator(argument.spelling())) {
556
+ Frame.SIZE_OPERATORS.includes(argument.spelling())) {
557
557
  return this.sizeFor(argument.spelling());
558
558
  }
559
559
  return this.live().call(argument, parameter);
@@ -153,13 +153,13 @@ export class FrameLazy extends FrameExpr {
153
153
  /**
154
154
  * `.#` counts the body's represented words (#429). `.##` sums their native
155
155
  * Sizes without execution or evaluation-site registration; an empty body
156
- * retains Size 1. Residual alternates complete stored-word Sizes; Demi
156
+ * retains Size 1. Residual alternates complete stored-word Sizes; Denum
157
157
  * derives from those observations (011.18c). The operator reaches a closure
158
158
  * as its argument and is answered before its body runs.
159
159
  */
160
160
  sizeOperator(argument) {
161
161
  if (argument instanceof FrameSymbol && argument.is.address === true &&
162
- Frame.isSizeOperator(argument.spelling())) {
162
+ Frame.SIZE_OPERATORS.includes(argument.spelling())) {
163
163
  return this.sizeFor(argument.spelling());
164
164
  }
165
165
  return undefined;
@@ -145,7 +145,7 @@ export class FrameList extends Frame {
145
145
  /** Immediate count is unchanged; Size and residual share native child sizes. */
146
146
  sizeFor(key) {
147
147
  const failure = this.observationError();
148
- if (failure && Frame.isSizeOperator(key))
148
+ if (failure && Frame.SIZE_OPERATORS.includes(key))
149
149
  return failure;
150
150
  if (key === Frame.kCOUNT) {
151
151
  const elements = this.sizeElements();
@@ -27,17 +27,17 @@ const recognizeName = (symbol, source = "") => {
27
27
  return { disposition: ScanDisposition.CompleteRedispatch };
28
28
  }
29
29
  // `#` begins a comment except where it spells a size operator, `.#`, `.##`
30
- // `.###` or `.####` (011.18). A fifth hash starts a comment;
31
- // `.foo#bar` still ends at its first hash.
32
- if (Frame.SIZE_OPERATORS.includes(source + char)) {
33
- return { disposition: ScanDisposition.Consume };
30
+ // `.###`, `.####` or the Count binding `.#%` (011.18, 007.40). A fifth hash
31
+ // starts a comment; `.foo#bar` still ends at its first hash.
32
+ // `.#%%` cannot be split back into `.#` and `%%` once `%` is consumed, so it
33
+ // is refused rather than read as `.#%` before a `%`: write `.# %%`.
34
+ if (source === Frame.kBIND && char === "%") {
35
+ return {
36
+ disposition: ScanDisposition.Error,
37
+ message: "`.#%%` is ambiguous: write `.# %%` or `.#% %`",
38
+ };
34
39
  }
35
- // A single hash followed by decimal digits is the ranked hash `.#n`
36
- // (occurrence/figure 007.32). Only the lone `#` takes digits: `.##2` is
37
- // `.##` and then the count 2, as before, and `.#2x` is `.#2` then `x`.
38
- // The spelling is canonical decimal, one name per rung: a zero ends the name,
39
- // so `.#05` is `.#0` and then the number 5.
40
- if (/^#(|[1-9][0-9]*)$/.test(source) && /^[0-9]$/.test(char)) {
40
+ if (Frame.SIZE_OPERATORS.includes(source + char)) {
41
41
  return { disposition: ScanDisposition.Consume };
42
42
  }
43
43
  if (source.startsWith(Frame.kCOUNT)) {
@@ -289,7 +289,7 @@ export class FrameSymbol extends FrameAtom {
289
289
  // A size operator answers for the receiver itself rather than looking a
290
290
  // name up, so the scope a value was read from never answers for it (#411).
291
291
  // Only an address is one, since the lexer looks `#` up as the comment.
292
- if (this.is.address === true && Frame.isSizeOperator(this.data)) {
292
+ if (this.is.address === true && Frame.SIZE_OPERATORS.includes(this.data)) {
293
293
  return context.referent().sizeFor(this.data);
294
294
  }
295
295
  // A dotted arithmetic operator is the operator itself: `xs ./ 3` is