hclang 0.49.0 → 0.51.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.
- package/esm/lib/bundle/hc-sources.js +509 -538
- package/esm/lib/execute/denum-prologue.js +3 -15
- package/esm/lib/execute/router-prologue.js +14 -18
- package/esm/lib/frames/denum-observers.js +181 -0
- package/esm/lib/frames/fourth-hash.js +24 -12
- package/esm/lib/frames/frame-name.js +12 -20
- package/esm/lib/frames/frame.js +31 -2
- package/esm/lib/frames.js +2 -0
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -74,14 +74,13 @@ export function denumClass() {
|
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Constructs a Denum of any arity with the HC class: `Denum [count, loads]`.
|
|
77
|
-
*
|
|
78
|
-
* right]` builds; any other nonzero number gives the channel Denum (007.27).
|
|
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
|
|
83
|
+
export function constructDenum(count, loads) {
|
|
85
84
|
const constructor = denumClass();
|
|
86
85
|
if (constructor.isFailedResult() || constructor.observationError()) {
|
|
87
86
|
return constructor;
|
|
@@ -89,15 +88,4 @@ export function constructDenumLoads(count, loads) {
|
|
|
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 Denum with the HC class: `Denum [count, left, right]`.
|
|
94
|
-
*
|
|
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.
|
|
99
|
-
*/
|
|
100
|
-
export function constructDenum(count, left, right) {
|
|
101
|
-
return constructDenumLoads(count, [left, right]);
|
|
102
|
-
}
|
|
103
|
-
installDenumConstructor(constructDenumLoads);
|
|
91
|
+
installDenumConstructor(constructDenum);
|
|
@@ -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
|
|
29
|
-
* instance from channels already known to be
|
|
30
|
-
* or copying them
|
|
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
|
|
32
|
+
export const ROUTER_BUILDER = "router-instance";
|
|
34
33
|
let loaded;
|
|
35
|
-
let
|
|
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
|
|
57
|
-
if (
|
|
58
|
-
return Frame.error(`$!.router-prologue-missing ${
|
|
55
|
+
const instance = namespace.getOwn(ROUTER_BUILDER);
|
|
56
|
+
if (instance.is.missing) {
|
|
57
|
+
return Frame.error(`$!.router-prologue-missing ${ROUTER_BUILDER}`);
|
|
59
58
|
}
|
|
60
|
-
|
|
59
|
+
builder = instance;
|
|
61
60
|
return constructor;
|
|
62
61
|
}
|
|
63
62
|
/**
|
|
@@ -94,8 +93,8 @@ 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
|
|
98
|
-
*
|
|
96
|
+
* The channels of an instance of the shipped class, for `.####` (007.27);
|
|
97
|
+
* undefined for anything else.
|
|
99
98
|
*
|
|
100
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
|
|
@@ -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
|
|
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 (!
|
|
144
|
+
if (!builder)
|
|
146
145
|
return Frame.error("$!.router-unavailable /");
|
|
147
|
-
|
|
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);
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Geometric observers of a Count-bound Denum (occurrence/figure 007.41b,
|
|
3
|
+
* 007.41c). They read a Denum and answer numbers and lists, and change nothing
|
|
4
|
+
* native.
|
|
5
|
+
*
|
|
6
|
+
* Each observer first applies the real Count binding `.#%` to its receiver,
|
|
7
|
+
* so every one of them reads the same bound loads `B = (C; [b0, …, b(C−1)])`,
|
|
8
|
+
* and every failure of `.#%` (a receiver that is not a Denum, Count zero, a
|
|
9
|
+
* Count past the binding capacity) is answered as it is. The six spellings
|
|
10
|
+
* pair a Size-like squared magnitude (`##…`) with a Residual-like list of
|
|
11
|
+
* signed coordinates (`###…`) for three geometries:
|
|
12
|
+
*
|
|
13
|
+
* | Geometry | Size-like | Residual-like | Count domain |
|
|
14
|
+
* | --- | --- | --- | --- |
|
|
15
|
+
* | centered simplex `%` | `.##%` | `.###%` | C ≥ 1 (C = 1 is zero) |
|
|
16
|
+
* | Cayley–Dickson imaginaries `%%` | `.##%%` | `.###%%` | C = 2ⁿ |
|
|
17
|
+
* | cross-polytope `%%%` | `.##%%%` | `.###%%%` | C = 2n, one load per vertex |
|
|
18
|
+
*
|
|
19
|
+
* Return types (007.41b §2): a squared magnitude is exact and nonnegative, a
|
|
20
|
+
* FrameCount when whole and a FrameRational otherwise. Coordinates are a fresh
|
|
21
|
+
* array of signed numbers, never a Denum: a FrameInt or FrameRational when the
|
|
22
|
+
* coordinate is rational, and an IEEE double (FrameNumber) only where it is
|
|
23
|
+
* irrational, which happens only for Cayley–Dickson coordinates. No native
|
|
24
|
+
* observer, operator or Denum load changes, and no algebra product is
|
|
25
|
+
* installed.
|
|
26
|
+
*
|
|
27
|
+
* @module
|
|
28
|
+
*/
|
|
29
|
+
import { Frame } from "./frame.js";
|
|
30
|
+
import { FrameArray } from "./frame-array.js";
|
|
31
|
+
import { FrameCount } from "./frame-count.js";
|
|
32
|
+
import { FrameInt } from "./frame-int.js";
|
|
33
|
+
import { FrameNumber } from "./frame-number.js";
|
|
34
|
+
import { FrameRational } from "./frame-rational.js";
|
|
35
|
+
import { boundLoads } from "./fourth-hash.js";
|
|
36
|
+
/** An exact nonnegative magnitude: a Count when whole, a rational otherwise. */
|
|
37
|
+
function magnitude(num, den) {
|
|
38
|
+
const value = FrameRational.create(num, den);
|
|
39
|
+
return value instanceof FrameInt ? new FrameCount(value.data) : value;
|
|
40
|
+
}
|
|
41
|
+
/** The exact square root of a nonnegative bigint, or undefined. */
|
|
42
|
+
function exactRoot(value) {
|
|
43
|
+
if (value < 2n)
|
|
44
|
+
return value;
|
|
45
|
+
let root = value;
|
|
46
|
+
let next = (root + 1n) / 2n;
|
|
47
|
+
while (next < root) {
|
|
48
|
+
root = next;
|
|
49
|
+
next = (root + value / root) / 2n;
|
|
50
|
+
}
|
|
51
|
+
return root * root === value ? root : undefined;
|
|
52
|
+
}
|
|
53
|
+
const sum = (values) => values.reduce((total, value) => total + value, 0n);
|
|
54
|
+
/**
|
|
55
|
+
* Centered simplex, `.##%`: `Q_S = (C·Σbᵢ² − S²)/(C−1)` with `S = Σbᵢ`, the
|
|
56
|
+
* squared length of `Σbᵢvᵢ` over the C unit vertices of a centered regular
|
|
57
|
+
* simplex. Count 1 is degenerate and answers 0.
|
|
58
|
+
*
|
|
59
|
+
* It is also the Cayley–Dickson norm `.##%%`: the Helmert map φ_C is an
|
|
60
|
+
* isometry, so `N(φ_C(B)) = Σxₖ²` equals this form exactly. The identity is
|
|
61
|
+
* checked by test rather than computed twice.
|
|
62
|
+
*/
|
|
63
|
+
function simplexSize(loads) {
|
|
64
|
+
const c = BigInt(loads.length);
|
|
65
|
+
if (c === 1n)
|
|
66
|
+
return new FrameCount(0n);
|
|
67
|
+
const total = sum(loads);
|
|
68
|
+
const squares = sum(loads.map((load) => load * load));
|
|
69
|
+
return magnitude(c * squares - total * total, c - 1n);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Centered simplex, `.###%`: the centered coefficients `zᵢ = bᵢ − S/C`, whose
|
|
73
|
+
* numerators over C are `C·bᵢ − S` (007.41b §3). They sum to zero. They are
|
|
74
|
+
* coefficients on the C unit vertices, not orthonormal coordinates, so `.##%`
|
|
75
|
+
* is their norm in the simplex Gram metric, `C/(C−1)·Σzᵢ²` (007.41e).
|
|
76
|
+
*/
|
|
77
|
+
function simplexResidual(loads) {
|
|
78
|
+
const c = BigInt(loads.length);
|
|
79
|
+
const total = sum(loads);
|
|
80
|
+
return new FrameArray(loads.map((load) => FrameRational.create(c * load - total, c)));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The Helmert numerators `sₖ = b₀ + … + b(k−1) − k·bₖ`, k = 1 … C−1, of the
|
|
84
|
+
* fixed-sign Helmert basis the 007.41 experiment's φ_C uses.
|
|
85
|
+
*/
|
|
86
|
+
function helmertNumerators(loads) {
|
|
87
|
+
const numerators = [];
|
|
88
|
+
let prefix = 0n;
|
|
89
|
+
for (let k = 1; k < loads.length; k++) {
|
|
90
|
+
prefix += loads[k - 1];
|
|
91
|
+
numerators.push(prefix - BigInt(k) * loads[k]);
|
|
92
|
+
}
|
|
93
|
+
return numerators;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Cayley–Dickson, `.###%%`: the coefficients `[0, x₁, …, x(C−1)]` of
|
|
97
|
+
* `x = φ_C(B)` on the basis `e₀ = 1, e₁, …`, with
|
|
98
|
+
* `xₖ = sₖ·√(C/((C−1)k(k+1)))`. Writing `d = (C−1)k(k+1)`, that is
|
|
99
|
+
* `sₖ·√(C·d)/d`, so a coordinate is the exact rational `sₖ·√m/d` when
|
|
100
|
+
* `m = C·d` is a perfect square, and a double otherwise, computed as the
|
|
101
|
+
* 007.41 experiment computes it. The real part is the exact 0. A double past
|
|
102
|
+
* the finite range is refused as `$!.numeric-range .###%%`, though `.##%%` of
|
|
103
|
+
* the same Denum stays exact: the two readings have different ranges by
|
|
104
|
+
* design (007.41e).
|
|
105
|
+
*/
|
|
106
|
+
function cdResidual(loads) {
|
|
107
|
+
const c = loads.length;
|
|
108
|
+
const coordinates = [new FrameInt(0n)];
|
|
109
|
+
const scale = c > 1 ? Math.sqrt(c / (c - 1)) : 0;
|
|
110
|
+
for (const [index, s] of helmertNumerators(loads).entries()) {
|
|
111
|
+
const k = BigInt(index + 1);
|
|
112
|
+
const d = BigInt(c - 1) * k * (k + 1n);
|
|
113
|
+
const root = s === 0n ? 0n : exactRoot(BigInt(c) * d);
|
|
114
|
+
if (root !== undefined) {
|
|
115
|
+
coordinates.push(FrameRational.create(s * root, d));
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const kk = index + 1;
|
|
119
|
+
const value = (scale * Number(s)) / Math.sqrt(kk * (kk + 1));
|
|
120
|
+
if (!Number.isFinite(value)) {
|
|
121
|
+
return Frame.error("$!.numeric-range .###%%");
|
|
122
|
+
}
|
|
123
|
+
coordinates.push(new FrameNumber(value));
|
|
124
|
+
}
|
|
125
|
+
return new FrameArray(coordinates);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Cross-polytope, one load per vertex (007.41b §5.A): C = 2n loads sit on the
|
|
129
|
+
* vertices `+e₀ … +e(n−1), −e₀ … −e(n−1)`, so `bᵢ` and `b(i+n)` are opposite,
|
|
130
|
+
* and the antipodal residual is `rᵢ = bᵢ − b(i+n)`, i = 0 … n−1.
|
|
131
|
+
*/
|
|
132
|
+
function antipodalResidual(loads) {
|
|
133
|
+
const n = loads.length / 2;
|
|
134
|
+
return loads.slice(0, n).map((load, i) => load - loads[i + n]);
|
|
135
|
+
}
|
|
136
|
+
/** Whether C is a power of two, the Cayley–Dickson dimensions. */
|
|
137
|
+
const isPowerOfTwo = (c) => c > 0 && (c & (c - 1)) === 0;
|
|
138
|
+
/**
|
|
139
|
+
* The geometries by the `%` suffix that follows `##` or `###`. Their keys are
|
|
140
|
+
* `Frame.GEOMETRY_SUFFIXES`, from which `Frame.GEOMETRIC_OBSERVERS` is spelled.
|
|
141
|
+
* Odd C has no antipodal pairing, so `$!.denum-cross-count` refuses only this
|
|
142
|
+
* binding, not odd-dimensional cross-polytopes.
|
|
143
|
+
*/
|
|
144
|
+
export const GEOMETRIES = {
|
|
145
|
+
"%": {
|
|
146
|
+
domain: () => undefined,
|
|
147
|
+
size: simplexSize,
|
|
148
|
+
residual: simplexResidual,
|
|
149
|
+
},
|
|
150
|
+
"%%": {
|
|
151
|
+
domain: (c) => isPowerOfTwo(c) ? undefined : Frame.error("$!.denum-cd-count"),
|
|
152
|
+
size: simplexSize,
|
|
153
|
+
residual: cdResidual,
|
|
154
|
+
},
|
|
155
|
+
"%%%": {
|
|
156
|
+
domain: (c) => c % 2 === 0 ? undefined : Frame.error("$!.denum-cross-count"),
|
|
157
|
+
size: (loads) => new FrameCount(sum(antipodalResidual(loads).map((r) => r * r))),
|
|
158
|
+
residual: (loads) => new FrameArray(antipodalResidual(loads).map((r) => new FrameInt(r))),
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Answers one geometric observer of a source: binds it with `.#%`, answering
|
|
163
|
+
* that binding's failure as it is, checks the geometry's Count domain once,
|
|
164
|
+
* then reads the bound loads.
|
|
165
|
+
*
|
|
166
|
+
* @param source The observed Frame.
|
|
167
|
+
* @param key One of `Frame.GEOMETRIC_OBSERVERS`.
|
|
168
|
+
* @returns The observation, or an error.
|
|
169
|
+
*/
|
|
170
|
+
function observeGeometry(source, key) {
|
|
171
|
+
const residual = key.startsWith("###");
|
|
172
|
+
const geometry = GEOMETRIES[key.slice(residual ? 3 : 2)];
|
|
173
|
+
const loads = boundLoads(source);
|
|
174
|
+
if (loads instanceof Frame)
|
|
175
|
+
return loads;
|
|
176
|
+
const refusal = geometry.domain(loads.length);
|
|
177
|
+
if (refusal)
|
|
178
|
+
return refusal;
|
|
179
|
+
return residual ? geometry.residual(loads) : geometry.size(loads);
|
|
180
|
+
}
|
|
181
|
+
Frame.observeGeometry = observeGeometry;
|
|
@@ -50,7 +50,7 @@ function storedLoads(source) {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
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,
|
|
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.
|
|
@@ -127,6 +127,21 @@ export const DENUM_BINDING_CAPACITY = 65536n;
|
|
|
127
127
|
* @returns The bound Denum, or an error.
|
|
128
128
|
*/
|
|
129
129
|
export function bindDenumCount(source) {
|
|
130
|
+
const bound = boundLoads(source);
|
|
131
|
+
if (bound instanceof Frame)
|
|
132
|
+
return bound;
|
|
133
|
+
return construct(new FrameCount(BigInt(bound.length)), bound.map((load) => new FrameCount(load)));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The loads of `source.#%`, the C sums `bj = Σ ai` over `i mod C = j`, folded
|
|
137
|
+
* without building the bound Denum, or the binding's error in the order
|
|
138
|
+
* `bindDenumCount` documents. The geometric observers (007.41b) read these, so
|
|
139
|
+
* they consume the same genuine binding as `.#%` at no extra cost.
|
|
140
|
+
*
|
|
141
|
+
* @param source The observed Frame.
|
|
142
|
+
* @returns The C bound loads, or the binding's error.
|
|
143
|
+
*/
|
|
144
|
+
export function boundLoads(source) {
|
|
130
145
|
const failure = source.observationError();
|
|
131
146
|
if (failure)
|
|
132
147
|
return failure;
|
|
@@ -145,20 +160,17 @@ export function bindDenumCount(source) {
|
|
|
145
160
|
state.loads.forEach((load, index) => {
|
|
146
161
|
bound[index % arity] += load;
|
|
147
162
|
});
|
|
148
|
-
return
|
|
163
|
+
return bound;
|
|
149
164
|
}
|
|
150
165
|
/**
|
|
151
|
-
* The
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* `Denum [C, [load0, …]]`, where a load is the summed Size of a channel's
|
|
157
|
-
* children and an empty channel's load is 0. The binary router keeps the
|
|
158
|
-
* derived path, which already answers `Denum(C, L, R)`.
|
|
166
|
+
* The router path (007.27). A router of k channels routes to channel C mod k,
|
|
167
|
+
* which only a Denum of k loads follows, so an instance of the shipped
|
|
168
|
+
* `RotorRouter` class, of any number of channels, answers the Denum of its
|
|
169
|
+
* Count and channel loads, `Denum [C, [load0, …]]`, where a load is the summed
|
|
170
|
+
* Size of a channel's children and an empty channel's load is 0.
|
|
159
171
|
*
|
|
160
172
|
* Its Count is the children it holds; at Count zero it has no Denum, as the
|
|
161
|
-
* empty
|
|
173
|
+
* empty host has none. Each child's Size is read
|
|
162
174
|
* once, and a failed Size is answered as it is.
|
|
163
175
|
*
|
|
164
176
|
* @param source The observed Frame.
|
|
@@ -199,7 +211,7 @@ function channelRouterDenum(source) {
|
|
|
199
211
|
* caches the source, and reads each observer at most once.
|
|
200
212
|
*
|
|
201
213
|
* A derived source with Count zero is nil: a host with no children has no
|
|
202
|
-
* Denum, so `[].####` and `0.####` are nil while `(Denum [0, 0, 0]).####` is
|
|
214
|
+
* Denum, so `[].####` and `0.####` are nil while `(Denum [0, [0, 0]]).####` is
|
|
203
215
|
* present. No class can declare `.####` for itself; only the three observers
|
|
204
216
|
* are declarable (`FrameArray.OBSERVATION_KEYS`).
|
|
205
217
|
*
|
|
@@ -7,8 +7,14 @@ import { EvaluationScope } from "./evaluation-scope.js";
|
|
|
7
7
|
import { completeAtEnd, includeOrReserve } from "./atom-syntax.js";
|
|
8
8
|
import { authorizedReceiverWriteTarget } from "./bound-method.js";
|
|
9
9
|
import { ScanDisposition, } from "../scan.js";
|
|
10
|
+
/**
|
|
11
|
+
* Inside a name, `#` is an operator character like `%`. Elsewhere it opens a
|
|
12
|
+
* comment, but after the dot it spells the size operators `.#` … `.####`, the
|
|
13
|
+
* Count binding `.#%` and the geometric observers, so it joins the run.
|
|
14
|
+
*/
|
|
15
|
+
const isOperatorChar = (char) => char === Frame.kCOUNT || FrameOperator.Accepts(char);
|
|
10
16
|
/** A name accepts identifier and operator characters alike. */
|
|
11
|
-
const includes = (char) => FrameSymbol.SYMBOL_CHAR.test(char) ||
|
|
17
|
+
const includes = (char) => FrameSymbol.SYMBOL_CHAR.test(char) || isOperatorChar(char);
|
|
12
18
|
/** A name continues while its spelling stays one kind of identifier. */
|
|
13
19
|
const recognizeName = (symbol, source = "") => {
|
|
14
20
|
const char = symbol.toString();
|
|
@@ -26,23 +32,6 @@ const recognizeName = (symbol, source = "") => {
|
|
|
26
32
|
(source.endsWith("^") && source !== "<^")) {
|
|
27
33
|
return { disposition: ScanDisposition.CompleteRedispatch };
|
|
28
34
|
}
|
|
29
|
-
// `#` begins a comment except where it spells a size operator, `.#`, `.##`
|
|
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
|
-
}
|
|
40
|
-
if (Frame.SIZE_OPERATORS.includes(source + char)) {
|
|
41
|
-
return { disposition: ScanDisposition.Consume };
|
|
42
|
-
}
|
|
43
|
-
if (source.startsWith(Frame.kCOUNT)) {
|
|
44
|
-
return { disposition: ScanDisposition.CompleteRedispatch };
|
|
45
|
-
}
|
|
46
35
|
// `.^` needs no rule of its own: `^` is an operator character, so it is
|
|
47
36
|
// consumed and completed like any other name.
|
|
48
37
|
if (!includes(char)) {
|
|
@@ -53,9 +42,12 @@ const recognizeName = (symbol, source = "") => {
|
|
|
53
42
|
if (source.length === 0) {
|
|
54
43
|
return { disposition: ScanDisposition.Consume };
|
|
55
44
|
}
|
|
56
|
-
|
|
45
|
+
// An operator run is never split: `.%%%%`, `.##%%%%` and `.#####` are each
|
|
46
|
+
// one name, bound or not. An identifier ends where the kind changes, so
|
|
47
|
+
// `.foo#bar#` is `.foo` before a comment.
|
|
48
|
+
const startsWithOperator = isOperatorChar(source[0]);
|
|
57
49
|
const continuesIdentifier = char[0] === "-" && !startsWithOperator;
|
|
58
|
-
const sameKind =
|
|
50
|
+
const sameKind = isOperatorChar(char[0]) === startsWithOperator;
|
|
59
51
|
return {
|
|
60
52
|
disposition: continuesIdentifier || sameKind
|
|
61
53
|
? ScanDisposition.Consume
|
package/esm/lib/frames/frame.js
CHANGED
|
@@ -718,7 +718,8 @@ 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
|
|
721
|
+
* Native Count, Size, residual, derived Denum, the Count binding `.#%` and
|
|
722
|
+
* the geometric observers. Missing Count falls back to
|
|
722
723
|
* Size, and missing residual to Count parity; kinds with their own rules
|
|
723
724
|
* (lists, schemas, Denum, all) supply them explicitly (011.18k, 011.18m).
|
|
724
725
|
* Nil has no Count, so no residual or Denum.
|
|
@@ -754,7 +755,7 @@ export class Frame extends MetaFrame {
|
|
|
754
755
|
case Frame.kBIND:
|
|
755
756
|
return Frame.bindCount(this);
|
|
756
757
|
default:
|
|
757
|
-
return Frame.
|
|
758
|
+
return Frame.observeGeometry(this, key);
|
|
758
759
|
}
|
|
759
760
|
}
|
|
760
761
|
/** Nonnegative represented quantity; path tracks recursive containment only. */
|
|
@@ -1154,6 +1155,33 @@ Object.defineProperty(Frame, "kBIND", {
|
|
|
1154
1155
|
writable: true,
|
|
1155
1156
|
value: "#%"
|
|
1156
1157
|
});
|
|
1158
|
+
/**
|
|
1159
|
+
* The `%` suffixes of the geometric observers of a Count-bound Denum
|
|
1160
|
+
* (occurrence/figure 007.41b, 007.41c): the centered simplex `%`, the
|
|
1161
|
+
* Cayley–Dickson imaginaries `%%` and the cross-polytope `%%%`. They key
|
|
1162
|
+
* `GEOMETRIES` in `denum-observers.ts`.
|
|
1163
|
+
*/
|
|
1164
|
+
Object.defineProperty(Frame, "GEOMETRY_SUFFIXES", {
|
|
1165
|
+
enumerable: true,
|
|
1166
|
+
configurable: true,
|
|
1167
|
+
writable: true,
|
|
1168
|
+
value: [
|
|
1169
|
+
"%",
|
|
1170
|
+
"%%",
|
|
1171
|
+
"%%%",
|
|
1172
|
+
]
|
|
1173
|
+
});
|
|
1174
|
+
/**
|
|
1175
|
+
* The geometric observers: for each of `GEOMETRY_SUFFIXES`, the Size-like
|
|
1176
|
+
* `##` then the Residual-like `###`. Each reads `.#%` of its receiver.
|
|
1177
|
+
*/
|
|
1178
|
+
Object.defineProperty(Frame, "GEOMETRIC_OBSERVERS", {
|
|
1179
|
+
enumerable: true,
|
|
1180
|
+
configurable: true,
|
|
1181
|
+
writable: true,
|
|
1182
|
+
value: Frame
|
|
1183
|
+
.GEOMETRY_SUFFIXES.flatMap((suffix) => [`##${suffix}`, `###${suffix}`])
|
|
1184
|
+
});
|
|
1157
1185
|
/**
|
|
1158
1186
|
* The size operators, the only names spelled with `#` (#411). Each answers
|
|
1159
1187
|
* for its receiver through `sizeFor`, never through name lookup.
|
|
@@ -1168,6 +1196,7 @@ Object.defineProperty(Frame, "SIZE_OPERATORS", {
|
|
|
1168
1196
|
Frame.kRESIDUAL,
|
|
1169
1197
|
Frame.kDENUM,
|
|
1170
1198
|
Frame.kBIND,
|
|
1199
|
+
...Frame.GEOMETRIC_OBSERVERS,
|
|
1171
1200
|
]
|
|
1172
1201
|
});
|
|
1173
1202
|
/**
|
package/esm/lib/frames.js
CHANGED
|
@@ -28,6 +28,8 @@ 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
30
|
export { installDenumConstructor, installRouterRecognizer, observeDenum, } from "./frames/fourth-hash.js";
|
|
31
|
+
// Installs `Frame.observeGeometry`; the module exports no public API.
|
|
32
|
+
import "./frames/denum-observers.js";
|
|
31
33
|
export { FrameDecimal } from "./frames/frame-decimal.js";
|
|
32
34
|
export { FrameSequence } from "./frames/frame-sequence.js";
|
|
33
35
|
export { FrameTypedNumber } from "./frames/frame-typed-number.js";
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.51.0";
|