hclang 0.48.0 → 0.50.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,71 +1,71 @@
1
1
  /**
2
- * The Demi class, loaded from HC for the fourth hash.
2
+ * The Denum class, loaded from HC for the fourth hash.
3
3
  *
4
- * `.####` answers a Demi, and a Demi is an HC class, `Demi` in `hc/demi.hc`,
4
+ * `.####` answers a Denum, and a Denum is an HC class, `Denum` in `hc/denum.hc`,
5
5
  * not a native one (occurrence/figure 011.20). The frames package derives the
6
6
  * Count and loads natively but cannot run HC, so this module installs the
7
- * constructor it calls (`installDemiConstructor`).
7
+ * constructor it calls (`installDenumConstructor`).
8
8
  *
9
9
  * The class is read from the compiled-in bundle, not through a resource root,
10
10
  * so `.####` works in a bare `evaluate`, which has no root and imports nothing.
11
- * The file is evaluated the first time a Demi is constructed, once per
11
+ * The file is evaluated the first time a Denum is constructed, once per
12
12
  * process, the way an import evaluates a testdoc: its example lines are
13
13
  * dropped and the first failure fails the whole. It runs in a namespace of its
14
14
  * own, with no host bindings and no root, so it can read nothing but the
15
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 Demi requested
17
- * while the file is still loading is `$!.demi-prologue-reentrant`, because
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
18
  * the class cannot be defined by itself.
19
19
  *
20
20
  * What stays native is only what HC cannot say: reading `#`, `##` and `###`
21
21
  * in a fixed order with their absence and error rules, and checking that the
22
- * loads are whole. Everything a Demi does is in the HC source.
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, FrameExpr, installDemiConstructor, } 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
- export const DEMI_SOURCE = "hc/demi.hc";
30
+ export const DENUM_SOURCE = "hc/denum.hc";
31
31
  /** The name the file declares the constructor under. */
32
- export const DEMI_CLASS = "Demi";
32
+ export const DENUM_CLASS = "Denum";
33
33
  let loaded;
34
34
  let loading = false;
35
35
  /**
36
36
  * Evaluates class source in a namespace of its own, with no host bindings and
37
- * no root, answering its `Demi` or the failure. Uncached: `demiClass` keeps
37
+ * no root, answering its `Denum` or the failure. Uncached: `denumClass` keeps
38
38
  * the one result the process uses.
39
39
  *
40
40
  * @param source The source text, or undefined when the bundle lacks it.
41
41
  * @returns The constructor, or an error.
42
42
  */
43
- export function loadDemiClass(source) {
43
+ export function loadDenumClass(source) {
44
44
  if (source === undefined) {
45
- return Frame.error(`$!.demi-prologue-missing ${DEMI_SOURCE}`);
45
+ return Frame.error(`$!.denum-prologue-missing ${DENUM_SOURCE}`);
46
46
  }
47
47
  const namespace = new FrameArray([]);
48
48
  const result = evaluateSourceText(source, EvaluationScope.root(namespace));
49
49
  if (result.isFailedResult() || result.observationError())
50
50
  return result;
51
- const constructor = namespace.getOwn(DEMI_CLASS);
51
+ const constructor = namespace.getOwn(DENUM_CLASS);
52
52
  return constructor.is.missing
53
- ? Frame.error(`$!.demi-prologue-missing ${DEMI_CLASS}`)
53
+ ? Frame.error(`$!.denum-prologue-missing ${DENUM_CLASS}`)
54
54
  : constructor;
55
55
  }
56
56
  /**
57
- * The `Demi` constructor closure, evaluated from the bundle on first use.
57
+ * The `Denum` constructor closure, evaluated from the bundle on first use.
58
58
  *
59
59
  * @returns The constructor, or the error that loading it answered.
60
60
  */
61
- export function demiClass() {
61
+ export function denumClass() {
62
62
  if (loaded)
63
63
  return loaded;
64
64
  if (loading)
65
- return Frame.error("$!.demi-prologue-reentrant");
65
+ return Frame.error("$!.denum-prologue-reentrant");
66
66
  loading = true;
67
67
  try {
68
- loaded = loadDemiClass(HC_SOURCES.get(DEMI_SOURCE));
68
+ loaded = loadDenumClass(HC_SOURCES.get(DENUM_SOURCE));
69
69
  }
70
70
  finally {
71
71
  loading = false;
@@ -73,31 +73,19 @@ export function demiClass() {
73
73
  return loaded;
74
74
  }
75
75
  /**
76
- * Constructs a Demi of any arity with the HC class: `Demi [count, loads]`.
77
- * Two loads give the binary Demi, the same instance `Demi [count, left,
78
- * right]` builds; any other nonzero number gives the channel Demi (007.27).
76
+ * Constructs a Denum of any arity with the HC class: `Denum [count, loads]`.
77
+ * Every number of loads, one or more, is the same class (007.27, 007.40).
79
78
  *
80
79
  * @param count The full application Count.
81
80
  * @param loads The ordered channel loads.
82
81
  * @returns The new instance, or the class's failure.
83
82
  */
84
- export function constructDemiLoads(count, loads) {
85
- const constructor = demiClass();
83
+ export function constructDenum(count, loads) {
84
+ const constructor = denumClass();
86
85
  if (constructor.isFailedResult() || constructor.observationError()) {
87
86
  return constructor;
88
87
  }
89
88
  const state = new FrameArray([count, new FrameArray([...loads])]);
90
89
  return FrameExpr.answeredValue(constructor.call(state)).referent();
91
90
  }
92
- /**
93
- * Constructs a binary Demi with the HC class: `Demi [count, left, right]`.
94
- *
95
- * @param count The full application Count; the Demi 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.
99
- */
100
- export function constructDemi(count, left, right) {
101
- return constructDemiLoads(count, [left, right]);
102
- }
103
- installDemiConstructor(constructDemiLoads);
91
+ installDenumConstructor(constructDenum);
@@ -1,6 +1,6 @@
1
1
  import { Frame, FrameCount, FrameString, FrameSymbol, } from "../frames.js";
2
- // Installs the Demi class that `.####` constructs (011.20).
3
- import "./demi-prologue.js";
2
+ // Installs the Denum class that `.####` constructs (011.20).
3
+ import "./denum-prologue.js";
4
4
  // Installs the RotorRouter class that list division answers (007.27c).
5
5
  import "./router-prologue.js";
6
6
  import { EvalPipe, makeSourcePipe } from "./eval-pipe.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
@@ -25,14 +25,13 @@ export const ROUTER_SOURCE = "hc/rotor-router.hc";
25
25
  /** The name the file declares the constructor under. */
26
26
  export const ROUTER_CLASS = "RotorRouter";
27
27
  /**
28
- * The builders the class file declares beside its constructor, which make an
29
- * instance from channels already known to be admissible, without validating
30
- * or copying them: `binary-router` for two channels, `channel-router` for any
31
- * other number.
28
+ * The builder the class file declares beside its constructor, which makes an
29
+ * instance of any number of channels from channels already known to be
30
+ * admissible, without validating or copying them.
32
31
  */
33
- export const ROUTER_BUILDERS = ["binary-router", "channel-router"];
32
+ export const ROUTER_BUILDER = "router-instance";
34
33
  let loaded;
35
- let builders;
34
+ let builder;
36
35
  let loading = false;
37
36
  /**
38
37
  * Evaluates class source in a namespace of its own, answering its
@@ -53,11 +52,11 @@ export function loadRouterClass(source) {
53
52
  if (constructor.is.missing) {
54
53
  return Frame.error(`$!.router-prologue-missing ${ROUTER_CLASS}`);
55
54
  }
56
- const [binary, channel] = ROUTER_BUILDERS.map((key) => namespace.getOwn(key));
57
- if (binary.is.missing || channel.is.missing) {
58
- return Frame.error(`$!.router-prologue-missing ${ROUTER_BUILDERS}`);
55
+ const instance = namespace.getOwn(ROUTER_BUILDER);
56
+ if (instance.is.missing) {
57
+ return Frame.error(`$!.router-prologue-missing ${ROUTER_BUILDER}`);
59
58
  }
60
- builders = { binary, channel };
59
+ builder = instance;
61
60
  return constructor;
62
61
  }
63
62
  /**
@@ -94,10 +93,10 @@ export function constructRouter(channels) {
94
93
  return FrameExpr.answeredValue(constructor.call(channels)).referent();
95
94
  }
96
95
  /**
97
- * The channels of an instance of the shipped class with other than two
98
- * channels, for `.####` (007.27); undefined for anything else.
96
+ * The channels of an instance of the shipped class, for `.####` (007.27);
97
+ * undefined for anything else.
99
98
  *
100
- * Recognition mirrors the Demi's (007.25e): the source's own stored
99
+ * Recognition mirrors the Denum's (007.25e): the source's own stored
101
100
  * `channels`, a list of arrays, must rebuild through the constructor into a
102
101
  * router `==` to the source, fields and methods included. Nothing of the
103
102
  * source runs, so a record that only spells `channels` is not a router.
@@ -113,7 +112,7 @@ export function channelRouterChannels(source) {
113
112
  if (!(stored instanceof FrameArray))
114
113
  return undefined;
115
114
  const channels = stored.elements().map((channel) => channel.referent());
116
- if (channels.length === 0 || channels.length === 2)
115
+ if (channels.length === 0)
117
116
  return undefined;
118
117
  if (!channels.every((channel) => channel instanceof FrameArray)) {
119
118
  return undefined;
@@ -142,12 +141,9 @@ export function dealtRouter(channels) {
142
141
  if (constructor.isFailedResult() || constructor.observationError()) {
143
142
  return constructor;
144
143
  }
145
- if (!builders)
144
+ if (!builder)
146
145
  return Frame.error("$!.router-unavailable /");
147
- const build = channels.elements().length === 2
148
- ? builders.binary
149
- : builders.channel;
150
- return FrameExpr.answeredValue(build.call(channels)).referent();
146
+ return FrameExpr.answeredValue(builder.call(channels)).referent();
151
147
  }
152
148
  installDivisionCarrier(dealtRouter);
153
149
  installRouterRecognizer(channelRouterChannels);
@@ -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,76 @@ 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
- * 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
93
- * derive follows parity, so for k other than two it would not be the router's
94
- * 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
97
- * children and an empty channel's load is 0. The binary router keeps the
98
- * derived path, which already answers `Demi(C, L, R)`.
151
+ * The router path (007.27). A router of k channels routes to channel C mod k,
152
+ * which only a Denum of k loads follows, so an instance of the shipped
153
+ * `RotorRouter` class, of any number of channels, answers the Denum of its
154
+ * Count and channel loads, `Denum [C, [load0, …]]`, where a load is the summed
155
+ * Size of a channel's children and an empty channel's load is 0.
99
156
  *
100
- * Its Count is the children it holds; at Count zero it has no Demi, as the
101
- * empty binary router and the empty host have none. Each child's Size is read
157
+ * Its Count is the children it holds; at Count zero it has no Denum, as the
158
+ * empty host has none. Each child's Size is read
102
159
  * once, and a failed Size is answered as it is.
103
160
  *
104
161
  * @param source The observed Frame.
105
- * @returns The router's channel Demi, nil, an error, or undefined when the
162
+ * @returns The router's channel Denum, nil, an error, or undefined when the
106
163
  * source is not a channel router.
107
164
  */
108
- function channelRouterDemi(source) {
165
+ function channelRouterDenum(source) {
109
166
  const channels = recognizeRouter?.(source);
110
167
  if (!channels)
111
168
  return undefined;
@@ -123,52 +180,52 @@ function channelRouterDemi(source) {
123
180
  return size;
124
181
  const load = exactCount(size);
125
182
  if (!load)
126
- return Frame.error("$!.demi-observations");
183
+ return Frame.error("$!.denum-observations");
127
184
  loads.push(new FrameCount(load.data));
128
185
  }
129
186
  if (!construct)
130
- return Frame.error("$!.demi-unavailable");
187
+ return Frame.error("$!.denum-unavailable");
131
188
  return construct(new FrameCount(count), loads);
132
189
  }
133
190
  /**
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
191
+ * The fourth hash, `.####`. For a constructed Denum it is that Denum's own state
192
+ * (`intrinsicDenum`), Count zero included. For every other Frame it is derived
136
193
  * 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
194
+ * loads (s+r)/2 and (s−r)/2, and n itself is the Denum's Count, kept whole
138
195
  * rather than reduced to its parity (007.25c). It never folds, executes or
139
196
  * caches the source, and reads each observer at most once.
140
197
  *
141
198
  * 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
199
+ * Denum, so `[].####` and `0.####` are nil while `(Denum [0, [0, 0]]).####` is
143
200
  * present. No class can declare `.####` for itself; only the three observers
144
201
  * are declarable (`FrameArray.OBSERVATION_KEYS`).
145
202
  *
146
203
  * In order: a failure of the source or of any observer is answered as it is;
147
204
  * 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).
205
+ * are not exact Counts and an integer are `$!.denum-observations`; and loads
206
+ * that are negative or not whole are `$!.denum-coherence`. Only then is the
207
+ * Denum constructed (011.18b–m).
151
208
  *
152
209
  * @param source The observed Frame.
153
- * @returns A Demi, nil, or an error.
210
+ * @returns A Denum, nil, or an error.
154
211
  */
155
- export function observeDemi(source) {
212
+ export function observeDenum(source) {
156
213
  const failure = source.observationError();
157
214
  if (failure)
158
215
  return failure;
159
- const intrinsic = intrinsicDemi(source);
216
+ const intrinsic = intrinsicDenum(source);
160
217
  if (intrinsic)
161
218
  return intrinsic;
162
- const routed = channelRouterDemi(source);
219
+ const routed = channelRouterDenum(source);
163
220
  if (routed)
164
221
  return routed;
165
222
  const n = source.sizeFor(Frame.kCOUNT);
166
223
  if (n.observationError())
167
224
  return n;
168
225
  if (n === Frame.nil)
169
- return Frame.nil; // no Count, no Demi (011.18k)
226
+ return Frame.nil; // no Count, no Denum (011.18k)
170
227
  if (!(n instanceof FrameCount) || typeof n.data !== "bigint" || n.data < 0n) {
171
- return Frame.error("$!.demi-count");
228
+ return Frame.error("$!.denum-count");
172
229
  }
173
230
  if (n.data === 0n)
174
231
  return Frame.nil;
@@ -182,17 +239,18 @@ export function observeDemi(source) {
182
239
  return Frame.nil;
183
240
  if (!(s instanceof FrameCount) || !(r instanceof FrameInt) ||
184
241
  typeof s.data !== "bigint" || typeof r.data !== "bigint" || s.data < 0n)
185
- return Frame.error("$!.demi-observations");
242
+ return Frame.error("$!.denum-observations");
186
243
  const sum = s.data + r.data;
187
244
  const difference = s.data - r.data;
188
245
  if (sum < 0n || difference < 0n || sum % 2n !== 0n || difference % 2n !== 0n) {
189
- return Frame.error("$!.demi-coherence");
246
+ return Frame.error("$!.denum-coherence");
190
247
  }
191
248
  if (!construct)
192
- return Frame.error("$!.demi-unavailable");
249
+ return Frame.error("$!.denum-unavailable");
193
250
  return construct(new FrameCount(n.data), [
194
251
  new FrameCount(sum / 2n),
195
252
  new FrameCount(difference / 2n),
196
253
  ]);
197
254
  }
198
- Frame.demi = observeDemi;
255
+ Frame.denum = observeDenum;
256
+ Frame.bindCount = bindDenumCount;
@@ -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,
@@ -153,7 +153,7 @@ 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
  */
@@ -27,8 +27,16 @@ 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.
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
+ };
39
+ }
32
40
  if (Frame.SIZE_OPERATORS.includes(source + char)) {
33
41
  return { disposition: ScanDisposition.Consume };
34
42
  }
@@ -718,10 +718,10 @@ export class Frame extends MetaFrame {
718
718
  return this.is.error || this.is.cyclicReference ? this : undefined;
719
719
  }
720
720
  /**
721
- * Native Count, Size, residual and derived Demi. Missing Count falls back to
721
+ * Native Count, Size, residual and derived Denum. Missing Count falls back to
722
722
  * Size, and missing residual to Count parity; kinds with their own rules
723
- * (lists, schemas, Demi, all) supply them explicitly (011.18k, 011.18m).
724
- * Nil has no Count, so no residual or Demi.
723
+ * (lists, schemas, Denum, all) supply them explicitly (011.18k, 011.18m).
724
+ * Nil has no Count, so no residual or Denum.
725
725
  */
726
726
  sizeFor(key) {
727
727
  if (!Frame.SIZE_OPERATORS.includes(key))
@@ -749,8 +749,10 @@ export class Frame extends MetaFrame {
749
749
  const data = n.data;
750
750
  return typeof data === "bigint" ? Frame.signed(data % 2n) : Frame.nil;
751
751
  }
752
- case Frame.kDEMI:
753
- return Frame.demi(this);
752
+ case Frame.kDENUM:
753
+ return Frame.denum(this);
754
+ case Frame.kBIND:
755
+ return Frame.bindCount(this);
754
756
  default:
755
757
  return Frame.nil;
756
758
  }
@@ -1133,13 +1135,25 @@ Object.defineProperty(Frame, "kRESIDUAL", {
1133
1135
  writable: true,
1134
1136
  value: "###"
1135
1137
  });
1136
- /** Derived nullable Demi, an instance of the HC class in `hc/demi.hc` (011.20). */
1137
- Object.defineProperty(Frame, "kDEMI", {
1138
+ /** Derived nullable Denum, an instance of the HC class in `hc/denum.hc` (011.20). */
1139
+ Object.defineProperty(Frame, "kDENUM", {
1138
1140
  enumerable: true,
1139
1141
  configurable: true,
1140
1142
  writable: true,
1141
1143
  value: "####"
1142
1144
  });
1145
+ /**
1146
+ * kBIND is `.#%`, Count binding (occurrence/figure 007.39a, 007.40): a
1147
+ * Denum `(C; [a0, …])` with C > 0 answers the new Denum of C loads whose
1148
+ * load j sums every source load at an index congruent to j mod C. Only a
1149
+ * genuine Denum is bound; any other receiver is refused (`fourth-hash.ts`).
1150
+ */
1151
+ Object.defineProperty(Frame, "kBIND", {
1152
+ enumerable: true,
1153
+ configurable: true,
1154
+ writable: true,
1155
+ value: "#%"
1156
+ });
1143
1157
  /**
1144
1158
  * The size operators, the only names spelled with `#` (#411). Each answers
1145
1159
  * for its receiver through `sizeFor`, never through name lookup.
@@ -1152,7 +1166,8 @@ Object.defineProperty(Frame, "SIZE_OPERATORS", {
1152
1166
  Frame.kCOUNT,
1153
1167
  Frame.kLEAVES,
1154
1168
  Frame.kRESIDUAL,
1155
- Frame.kDEMI,
1169
+ Frame.kDENUM,
1170
+ Frame.kBIND,
1156
1171
  ]
1157
1172
  });
1158
1173
  /**
package/esm/lib/frames.js CHANGED
@@ -27,7 +27,7 @@ export { FrameObservation } from "./frames/frame-observation.js";
27
27
  export { FrameNumeric, NUMERIC_RANK, } from "./frames/frame-numeric.js";
28
28
  export { FrameInt } from "./frames/frame-int.js";
29
29
  export { FrameCount } from "./frames/frame-count.js";
30
- export { installDemiConstructor, installRouterRecognizer, observeDemi, } from "./frames/fourth-hash.js";
30
+ export { installDenumConstructor, installRouterRecognizer, observeDenum, } from "./frames/fourth-hash.js";
31
31
  export { FrameDecimal } from "./frames/frame-decimal.js";
32
32
  export { FrameSequence } from "./frames/frame-sequence.js";
33
33
  export { FrameTypedNumber } from "./frames/frame-typed-number.js";
@@ -1 +1 @@
1
- export const VERSION = "0.48.0";
1
+ export const VERSION = "0.50.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.48.0",
3
+ "version": "0.50.0",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",