hclang 0.37.3 → 0.38.1

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.
@@ -226,7 +226,8 @@ export const HC_SOURCES = new Map([
226
226
  "",
227
227
  "=== Schema Retrieval and Captures (implemented, #310)",
228
228
  "",
229
- "The `<>` property retrieves the schema attached to the binding:",
229
+ "The `<^>` property retrieves the schema attached to the binding; `.<>` observes",
230
+ "the runtime type:",
230
231
  "```",
231
232
  "; enum123.<^>",
232
233
  "# <1, 2, 3>",
@@ -690,14 +691,17 @@ export const HC_SOURCES = new Map([
690
691
  "; [.a 1] & {_}",
691
692
  "# []",
692
693
  "```",
693
- "`.#` and `.##` count the elements too, the immediate ones and the terminals",
694
- "below them, so neither counts a property. A terminal is an element that is not",
695
- "an aggregate, or an aggregate with no elements: the empty frame is one terminal,",
696
- "at the root or nested. A nested count contributes its own Size, including zero",
697
- "(`[[3], 0].##` is 3); other atoms contribute one. Every aggregate counts this",
698
- "way, a group as well as an array. A count is its own size, and any other value",
699
- "has none (#411, issue",
700
- "occurrence/figure 010.02)",
694
+ "`.#` counts immediate elements or represented words; properties do not count.",
695
+ "A missing Count rule falls back to native Size, including numbers, text, blobs,",
696
+ "bytes and opaque atoms. Explicit list, schema and all Count rules take precedence; `()` has no Count. `.##` measures represented",
697
+ "quantity: lists sum complete child Sizes, with Size 1 for an empty list. Numeric",
698
+ "magnitude, Unicode text length, blob bits and payload bytes have their own native",
699
+ "Sizes; schemas retain their description/alternative quantities. Other opaque",
700
+ "values have Size 1. `.###` alternates child Sizes on non-schema lists, or returns",
701
+ "Count parity (`.# mod 2`) on every other value with a Count; schemas have nil",
702
+ "residual, and `<>` observes as `[]`. `.####` derives a Demi, an instance of",
703
+ "the class in `hc/demi.hc`, returning nil at zero Count or nil residual and",
704
+ "propagating failed observations.",
701
705
  "```",
702
706
  "; [.meta 1; 2, 3] .#",
703
707
  "# 2",
@@ -710,7 +714,7 @@ export const HC_SOURCES = new Map([
710
714
  "; 5.#",
711
715
  "# 5",
712
716
  "; “abc”.#",
713
- "# ()",
717
+ "# 3",
714
718
  "```",
715
719
  "**Decision.** Canonical rendering puts the properties first, then the elements.",
716
720
  "This reverses the spelling this file carried before. It makes print order agree",
@@ -1071,6 +1075,14 @@ export const HC_SOURCES = new Map([
1071
1075
  "; Pt.peek [.n 7]",
1072
1076
  "# [7, 1]",
1073
1077
  "",
1078
+ "`Only a field is a method. An element is data the aggregate holds, so a closure",
1079
+ "read by index answers as itself, whether the aggregate is named or written in",
1080
+ "place, and calling it gives it no receiver.`",
1081
+ "; .inc {_ + 1};",
1082
+ "; .Box [.get {_^}; inc];",
1083
+ "; [Box.0 === inc, [inc].0 === inc, (Box & {_}).0 === inc, Box.0 4]",
1084
+ "# [<>, <>, <>, 5]",
1085
+ "",
1074
1086
  "`A functional copy is its own receiver, so its methods read the fields the copy",
1075
1087
  "holds rather than those of the value it was copied from.`",
1076
1088
  "; .Tally [.n 1; .read {_^.n}; .bump_ {@n (_^.n + 1);}];",
@@ -1094,6 +1106,219 @@ export const HC_SOURCES = new Map([
1094
1106
  "",
1095
1107
  ].join("\n"),
1096
1108
  ],
1109
+ [
1110
+ "hc/constructed-state.hc",
1111
+ [
1112
+ "#!/usr/bin/env hc",
1113
+ "```",
1114
+ "Demi constructed physical state: VACT witness and scope (Explore 022.06)",
1115
+ "",
1116
+ "Implements the corrected handoff in occurrence/explore 022.05a, pinned at",
1117
+ "9d966bd95a783849c0363d82ee295586e0ffc6db581815b443140d746843eec8:",
1118
+ "https://nightly.quilttest.com/b/protology/packages/occurrence/explore/tree/9d966bd95a783849c0363d82ee295586e0ffc6db581815b443140d746843eec8/issues/022-constructed-physical-state/022.05a-Hilary-VACT-correction-constructive-physical-state.md",
1119
+ "",
1120
+ "Construction -> specified observation -> vacted fact -> interpretation.",
1121
+ "Run from the repository root: `deno task hc hc/constructed-state.hc -t`.",
1122
+ "The assertions below are the reproducible software witness. They do not report",
1123
+ "an executed laboratory experiment. Importing this testdoc exports no new state",
1124
+ "class or observer: it uses native arrays, application (one-child append), Star",
1125
+ "(terminal Inlay), and the existing fourth hash.",
1126
+ "",
1127
+ "Uniform construction and exact observation contract",
1128
+ "",
1129
+ "Begin with the empty host E = []. For any already constructed finite hosts X",
1130
+ "and Y, construct X Y by appending Y as one immediate child, or X * Y by",
1131
+ "replacing each empty terminal of X with Y. Repetition of this recipe constructs",
1132
+ "arbitrary finite nested arrays: build each child, then append each to []. Shared",
1133
+ "children are permitted and contribute at every occurrence. There are no infinite",
1134
+ "Frames here. Ordinary properties may decorate nonterminal nodes; this observer",
1135
+ "ignores them. Inlay requires unadorned empty terminals: native Star refuses",
1136
+ "a metadata-only empty host, as checked below. Append/observation can still",
1137
+ "read such a host; it is outside the closed Inlay construction family. No declared hash methods, declared parents, cycles, or arbitrary",
1138
+ "property-editing operations are in the uniform contract. This is a domain for",
1139
+ "this construction/observation experiment, not a special ontology of pure Figures.",
1140
+ "Other finite Frames can have Demi readings; their constructor laws require their",
1141
+ "own domain checks. In particular, mixed-array append is illustrated below but",
1142
+ "mixed-array Star is outside this contract.",
1143
+ "",
1144
+ "For each host read Count n = X.#, Size S = X.##, and alternating residual",
1145
+ "A = X.###. An empty terminal has Size 1. A nonempty host has Size equal to",
1146
+ "the sum of its immediate child Sizes, and A alternates + and - across those",
1147
+ "children, starting +. Properties do not enter these sums. D(X) = X.#### is",
1148
+ "nil for the empty host; otherwise it has loads L = (S+A)/2, R = (S-A)/2 and",
1149
+ "phase p = 2 for even n (left next), 1 for odd n (right next). Read these with",
1150
+ "`.left`, `.right`, `.phase`. n is forgotten except for parity. Nesting,",
1151
+ "identities, properties and the distribution within each load are forgotten.",
1152
+ "```",
1153
+ "; .E []; .X [[], [[], []], []];",
1154
+ "; [E.#, E.##, E.###, E.####]",
1155
+ "# [0, 1, 0, ()]",
1156
+ "; [X.#, X.##, X.###, X.####.phase, X.####.left, X.####.right]",
1157
+ "# [3, 4, 0, 1, 2, 2]",
1158
+ "; .decorated [.label 99; [], [[], []], []];",
1159
+ "; [decorated.#### = X.####, decorated.label, X.#### = X.####]",
1160
+ "# [<>, 99, <>]",
1161
+ "; [(decorated * [[], []]).#### = (X * [[], []]).####, [.label 99;] * [[]]]",
1162
+ "# [<>, $!.star-metadata *]",
1163
+ "; .shared [[], []];",
1164
+ "; [shared, shared].#### = [[[], []], [[], []]].####",
1165
+ "# <>",
1166
+ "```",
1167
+ "Generation and selective compression",
1168
+ "",
1169
+ "No Demi is initialized when building X. The native reading derives from the",
1170
+ "constructed host. Equal readings can hide different nesting and even different",
1171
+ "Counts, while another construction gives a different reading.",
1172
+ "```",
1173
+ "; .A [[]]; .B [[[]]];",
1174
+ "; [A = B, A.#### = B.####, A.#### === B.####]",
1175
+ "# [(), <>, ()]",
1176
+ "; .C [[[], []], [[], []]]; .F [[], [], [], []];",
1177
+ "; [C.#, F.#, C = F, C.#### = F.####, A.#### = C.####]",
1178
+ "# [2, 4, (), <>, ()]",
1179
+ "; [“” A.####, “” C.####, “” [[], [[], []]].####]",
1180
+ "# [“Demi((),1,0)”, “Demi(<>,2,2)”, “Demi(<>,1,2)”]",
1181
+ "```",
1182
+ "Uniform append and Inlay, including successive compositions",
1183
+ "",
1184
+ "For any nonempty X in the contract, appending Y deposits Y.## into the active",
1185
+ "load and flips phase. This is precisely how native append adds one term to",
1186
+ "the Size sum and the alternating sum: (X Y).#### = (X.#### Y).",
1187
+ "It works for either parity, independent of the shape or size of Y.",
1188
+ "```",
1189
+ "; .Y [[], [], []];",
1190
+ "; [(A Y).#### = (A.#### Y), (C Y).#### = (C.#### Y), (X Y).#### = (X.#### Y)]",
1191
+ "# [<>, <>, <>]",
1192
+ "; [“” (A Y).####, “” (C Y).####, “” ((C Y) []).####]",
1193
+ "# [“Demi(<>,1,3)”, “Demi((),5,2)”, “Demi(<>,5,3)”]",
1194
+ "; ([5, “ab”] []).#### = ([5, “ab”].#### [])",
1195
+ "# <>",
1196
+ "```",
1197
+ "Inlay replaces every terminal with Y. Each immediate child's Size is multiplied",
1198
+ "by Y.##, so both alternating loads scale by that same quantity. A nonempty",
1199
+ "host retains its immediate Count and phase. Thus for every such X and Y,",
1200
+ "(X * Y).#### = X.####.scale_ (Y.##). For empty X, [] * Y is Y itself:",
1201
+ "the empty case is substitution, not scaling a missing state.",
1202
+ "These are uniform recipes for every finite input in the contract. Enumerating",
1203
+ "tests cannot establish their scope: the shared child-Size traversal and the",
1204
+ "specified append/substitution operations explain why the readings commute.",
1205
+ "```",
1206
+ "; [(A * Y).#### = (A.####.scale_ (Y.##)), (C * Y).#### = (C.####.scale_ (Y.##)), (X * Y).#### = (X.####.scale_ (Y.##))]",
1207
+ "# [<>, <>, <>]",
1208
+ "; [([] * Y) = Y, ([] * []).####, (X * []).#### = X.####]",
1209
+ "# [<>, (), <>]",
1210
+ "; (((C Y) * [[], []]) []).#### = (((C.#### Y).scale_ 2) [])",
1211
+ "# <>",
1212
+ "```",
1213
+ "Origin and channel names",
1214
+ "",
1215
+ "The empty host has no Demi, despite Size 1. Its first append generates a",
1216
+ "present reading. Applying nil is not the append update; a zero-load phase-2",
1217
+ "Demi is an explicit initialized-router convention, not a preconstruction state",
1218
+ "secretly stored in []. A zero Size deposit still changes routing phase.",
1219
+ "```",
1220
+ "; [([] []).####.phase, ([] []).####.left, ([] []).####.right]",
1221
+ "# [1, 1, 0]",
1222
+ "; [([] Y).#### = ([].#### Y), ([] * Y).#### = Y.####]",
1223
+ "# [(), <>]",
1224
+ "; Demis <- './hc/demi.hc';",
1225
+ "; ([] Y).#### = ((Demis.Demi [2, 0, 0]) Y)",
1226
+ "# <>",
1227
+ "; [“” [0].####, “” ([0].#### 0), [].#### = [0].####]",
1228
+ "# [“Demi((),0,0)”, “Demi(<>,0,0)”, ()]",
1229
+ "```",
1230
+ "For a proposed relabeling, exchange the loads AND toggle which named channel",
1231
+ "is next: J(p,L,R) = (3-p,R,L). Total load stays fixed and residual changes",
1232
+ "sign. J commutes with deposit and scale; this is equivariance of a named",
1233
+ "router representation, not invariance of its signed readout, not reversal of",
1234
+ "the host, and not a new native constructor. The following closure only checks",
1235
+ "that explicit relabeling using the existing Demi class.",
1236
+ "```",
1237
+ "; .swap {.d _; Demis.Demi [(d.phase = 2) ? {1} : {2}, d.right, d.left]};",
1238
+ "; .q [[], [[], []]].####;",
1239
+ "; [“” q, “” (swap q), (swap q).## = q.##, (swap q).### = (0 - q.###)]",
1240
+ "# [“Demi(<>,1,2)”, “Demi((),2,1)”, <>, <>]",
1241
+ "; [(swap (q Y)) = ((swap q) Y), (swap ((q Y) [])) = (((swap q) Y) []), (swap (q.scale_ 3)) = ((swap q).scale_ 3), (swap (swap q)) = q]",
1242
+ "# [<>, <>, <>, <>]",
1243
+ "```",
1244
+ "Future sufficiency, at its earned scope",
1245
+ "",
1246
+ "For equal nonempty D readings, equal loads imply equal total Size and equal",
1247
+ "phase. The append recipe uses only those fields and the appended Size; the",
1248
+ "Inlay recipe uses only those fields and the replacement Size. Consequently",
1249
+ "any finite sequence of the SAME right-append and right-Inlay constructions",
1250
+ "preserves D equality. If both starting hosts are empty, they are the same",
1251
+ "empty construction and the empty rules apply. A nonempty host in the primary",
1252
+ "domain has positive total load, so it cannot collide with the nil empty reading.",
1253
+ "One may also use equivalent hosts as common right operands, since Size agrees;",
1254
+ "the empty case must be treated separately (its Size is 1, not zero).",
1255
+ "This is a uniform construction/observer relationship, not a claim that every",
1256
+ "HC observer or arbitrary operation factors through D. Count already separates",
1257
+ "C and F; inspecting stored metadata can separate decorated and undecorated X.",
1258
+ "```",
1259
+ "; [((A Y) * Y).#### = ((B Y) * Y).####, (((C []) * Y) A).#### = (((F []) * Y) A).####]",
1260
+ "# [<>, <>]",
1261
+ "; [C.#### = F.####, C.# = F.#, decorated.#### = X.####, decorated = X]",
1262
+ "# [<>, (), <>, ()]",
1263
+ "```",
1264
+ "Physically realizable readout (proposed material apparatus)",
1265
+ "",
1266
+ "Use a finite tray tree with one unit stick for each empty terminal. To read a",
1267
+ "nonempty host, count the sticks in each immediate child tray, deposit that many",
1268
+ "unit marks in alternating left and right bins, and toggle a two-position pointer",
1269
+ "after EACH child. Start left. Read bin populations as L,R and the next-bin",
1270
+ "pointer as phase 2 or 1. Read n by counting immediate trays, S by counting all",
1271
+ "terminal sticks, and A by subtracting the bin populations. No separately",
1272
+ "supplied state vector or stochastic routing law is needed. The empty host's",
1273
+ "one terminal stick is not an immediate child deposit: report no Demi until",
1274
+ "construction places a first child. A physical pointer's initial left choice",
1275
+ "is part of this selected measurement convention.",
1276
+ "",
1277
+ "Append is placing a child tray and routing its counted terminal sticks into",
1278
+ "the next bin. Inlay is replacing EACH terminal stick with a copy of Y's tray",
1279
+ "tree, preserving its immediate ancestor's bin assignment. Replace each old",
1280
+ "bin mark with Y.## marks; retain the pointer. Do not route all replacement",
1281
+ "sticks globally one at a time: that would implement a different phase rule.",
1282
+ "For empty-host Inlay, replace the entire empty terminal and reread Y afresh.",
1283
+ "This finite procedure realizes the same counts and compositions without",
1284
+ "assuming the mathematical update equations as measurements. Recount the tray",
1285
+ "leaves and compare with the bins after each act; the numerical examples above",
1286
+ "supply a reproducible readout script (C starts 2,2,left; append Y gives",
1287
+ "5,2,right; append [] gives 5,3,left).",
1288
+ "",
1289
+ "Finite resources bound any performed run. Stick loss, misrouting, unequal",
1290
+ "units, shared subtrees mistaken for single occurrences, and changing declared",
1291
+ "observers are possible failures of the realization. The software models exact",
1292
+ "counts and occurrence copies; it measures no material noise or physical law.",
1293
+ "",
1294
+ "Five-criterion verdict and evidence scope",
1295
+ "",
1296
+ "1. Derived: VACTED by execution for the examples; uniformly vacted under the",
1297
+ " construction/observer contract. Hosts are built before their Demi is read.",
1298
+ "2. Compressive: VACTED by distinct equal-reading constructions. Representation",
1299
+ " has two unbounded Counts plus parity; fixed dimension is not bounded bits.",
1300
+ "3. Forced update: VACTED by execution for the displayed compositions; uniformly",
1301
+ " vacted by the append and substitution recipes on the declared domain.",
1302
+ "4. Origin: VACTED for no supplied host Demi and the first-construction boundary.",
1303
+ " Channel relabeling is CONDITIONALLY VACTED as the explicit router",
1304
+ " equivariance above. Full origin/gauge invariance is NOT YET VACTED.",
1305
+ "5. Earned forgetting: uniformly vacted for the specified future constructor",
1306
+ " language and D observations, with executable witnesses. Sufficiency for all",
1307
+ " other HC observations is false, as the Count counterexample demonstrates.",
1308
+ "",
1309
+ "Actual apparatus executed here: the HC interpreter and testdoc harness, using",
1310
+ "native Frame construction and .####. The command's per-claim output and final",
1311
+ "pass/fail totals are the run evidence; the PR records the runtime and results.",
1312
+ "The material stick/bin apparatus is ONLY PROPOSED AS PHYSICALLY REALIZABLE;",
1313
+ "performed laboratory execution is NOT YET VACTED. The existential physical",
1314
+ "interpretation is CONDITIONALLY VACTED on that explicit realization. This",
1315
+ "claims neither uniqueness nor the physics of our universe. Supplementary",
1316
+ "update equations explain the observation; they are not a theorem-first gate.",
1317
+ "```",
1318
+ "[] = []",
1319
+ "",
1320
+ ].join("\n"),
1321
+ ],
1097
1322
  [
1098
1323
  "hc/cqml.hc",
1099
1324
  [
@@ -1159,6 +1384,271 @@ export const HC_SOURCES = new Map([
1159
1384
  "",
1160
1385
  ].join("\n"),
1161
1386
  ],
1387
+ [
1388
+ "hc/demi.hc",
1389
+ [
1390
+ "#!/usr/bin/env hc",
1391
+ "```",
1392
+ "Demi (occurrence/figure 011.20)",
1393
+ "",
1394
+ "A Demi is a closed two-channel state: a phase and two loads, left and right.",
1395
+ "Applying a Demi to a Frame deposits that Frame's Size into the active load and",
1396
+ "flips the phase, so a Demi follows alternating construction one observation at",
1397
+ "a time. It is what the fourth hash answers: `x.####` is the Demi of x's Count,",
1398
+ "Size and residual, with left load (Size + residual)/2 and right load",
1399
+ "(Size − residual)/2.",
1400
+ "",
1401
+ "`Demi` is an ordinary HC class: a constructor closure answering a fresh",
1402
+ "aggregate whose fields are its state and whose methods are the class. Nothing",
1403
+ "about it is native. The fourth hash keeps only its derivation and builds its",
1404
+ "answer with this constructor, which the evaluator reads from this file, compiled",
1405
+ "in, the first time `.####` needs one. So this file is both the definition every",
1406
+ "evaluator uses and its specification, and it works without a resource root.",
1407
+ "Import it to construct Demis directly: `Demis <- './hc/demi.hc'`, then",
1408
+ "`Demis.Demi [2, 0, 0]`.",
1409
+ "",
1410
+ "**State.** `Demi [phase, left, right]` takes three Counts. The phase is the",
1411
+ "least positive Count of its parity (011.18g): 2 when even, left next, and 1",
1412
+ "when odd, right next. It is a Count rather than all or nil because a field",
1413
+ "cannot hold nil, and a Count keeps the odd phase present: a Demi in phase 1 is",
1414
+ "a value, unlike the nil `.####` answers for a Frame with no Demi. Anything else",
1415
+ "is refused with `invalid-demi`, a missing name, as Figures refuses an",
1416
+ "unsupported host. The fields are the whole state, so two Demis are `=` exactly",
1417
+ "when their fields are.",
1418
+ "",
1419
+ "**Observers.** A Demi declares its own Count, Size and residual (011.20): its",
1420
+ "phase, its total load L+R, and the signed difference L−R. An aggregate",
1421
+ "otherwise observes its elements, and a Demi has none, so without these it",
1422
+ "would observe as 0, 1, 0. Its fourth hash derives from them like any Frame's,",
1423
+ "so `d.####` rebuilds the same Demi.",
1424
+ "",
1425
+ "**Application**, `d x`: observe x's Size once, deposit it into the active load,",
1426
+ "flip the phase. A Size of zero still flips. If x has no Size, its failure is",
1427
+ "the answer rather than a deposit. It is a mutating method, `apply_`, so",
1428
+ "through a name, `d x` is a functional update: it answers a new Demi and leaves",
1429
+ "d unchanged, holding exactly the same three fields.",
1430
+ "",
1431
+ "**Scaling**, `d.scale_ k`: multiply both loads by a Count k, keeping the",
1432
+ "phase. It is the numerical shadow of Star: `(x * y).####` is",
1433
+ "`x.####.scale_ (y.##)` for a nonempty host x. Scaling is a method because a",
1434
+ "class cannot declare an operator, so `d * k` is ordinary Star, which refuses",
1435
+ "an aggregate with properties.",
1436
+ "",
1437
+ "**Text.** A Demi prints as what it is, an aggregate of fields and methods, and",
1438
+ "that reads back as the same Demi. As text it reads `Demi(<>,12,3)`, with the",
1439
+ "phase spelled as the orientation it stands for.",
1440
+ "",
1441
+ "**Methods read their own state through `_^`.** A bare name inside a method is",
1442
+ "looked up on the argument first (spec 7), and a Demi is applied to arbitrary",
1443
+ "Frames, so a bare `left` could read the argument's field. `_^` is the receiver",
1444
+ "from a method's body, and `_^^` from a block one level in, because carets",
1445
+ "count lexically (spec a06). What a branch needs is bound as a local at method",
1446
+ "level, where nested blocks read it.",
1447
+ "```",
1448
+ ".Demi {.p (_ .0); .l (_ .1); .r (_ .2);",
1449
+ " ((((p = 2) : {p = 1}) ? {p ~ (0.<>)}) ? {(l ~ (0.<>)) ? {r ~ (0.<>)}}) ? {[",
1450
+ " .phase p;",
1451
+ " .left l;",
1452
+ " .right r;",
1453
+ " .# {_^.phase};",
1454
+ " .## {_^.left + _^.right};",
1455
+ " .### {_^.left - _^.right};",
1456
+ " .apply_ {.s (_ .##); .l (_^ .left); .r (_^ .right);",
1457
+ " (s ~ (0.<>)) ? {((_^^ .phase) = 2) ? {@left (l + s); @phase 1;} : {@right (r + s); @phase 2;}; _^^} : {s}};",
1458
+ " .scale_ {.k _; .l (_^ .left); .r (_^ .right);",
1459
+ " (k ~ (0.<>)) ? {@left (l * k); @right (r * k); _^^} : {invalid-scale}};",
1460
+ " .toText {“Demi(” (((_^ .phase) = 2) ? {“<>”} : {“()”}) “,” (_^ .left) “,” (_^ .right) “)”}",
1461
+ " ]} : {invalid-demi}};",
1462
+ "```",
1463
+ "## Construction",
1464
+ "",
1465
+ "A Demi holds exactly its three fields. Each instance is its own: two built",
1466
+ "from the same constructor share nothing",
1467
+ "```",
1468
+ "; .d (Demi [2, 0, 0]);",
1469
+ "; [d.phase, d.left, d.right]",
1470
+ "# [2, 0, 0]",
1471
+ "; .a (Demi [2, 5, 3]); .b (Demi [1, 7, 0]);",
1472
+ "; [“” a, “” b, a.left, b.left]",
1473
+ "# [“Demi(<>,5,3)”, “Demi((),7,0)”, 5, 7]",
1474
+ "```",
1475
+ "Anything but three Counts with phase 1 or 2 is refused",
1476
+ "```",
1477
+ "; Demi [3, 0, 0]",
1478
+ "# $!.name-missing “$:Frame.0.invalid-demi”;",
1479
+ "; [Demi [2, (0 - 1), 0], Demi [2, (5 - 3), 0], Demi [2, 0], Demi 5, Demi [(5 - 3), 0, 0]]",
1480
+ "# [$!.name-missing “$:Frame.0.invalid-demi”;, $!.name-missing “$:Frame.0.invalid-demi”;, $!.name-missing “$:Frame.0.invalid-demi”;, $!.name-missing “$:Frame.0.invalid-demi”;, $!.name-missing “$:Frame.0.invalid-demi”;]",
1481
+ "```",
1482
+ "## Application",
1483
+ "",
1484
+ "Each application deposits the argument's Size into the active load and flips",
1485
+ "the phase. The receiver is left as it was",
1486
+ "```",
1487
+ "; “” (d [5, 3])",
1488
+ "# “Demi((),8,0)”",
1489
+ "; “” d",
1490
+ "# “Demi(<>,0,0)”",
1491
+ "; “” (((d 5) 3) 7)",
1492
+ "# “Demi((),12,3)”",
1493
+ "```",
1494
+ "A Size of zero deposits nothing and still flips, in both phases",
1495
+ "```",
1496
+ "; [(d 0).phase, ((d 0) 0).phase, (d 0).left, ((d 0) 0).right]",
1497
+ "# [1, 2, 0, 0]",
1498
+ "```",
1499
+ "Any Frame is applied by its Size, measured without running it: text, the",
1500
+ "empty aggregate and all (Size 1 each), nested aggregates, a closure (one per",
1501
+ "word, so `{5 + 3}` is 9), empty text, and loads too large for a machine integer",
1502
+ "```",
1503
+ "; “” ((((((d “hello”) []) <>) [[1, 2], [3]]) {5 + 3}) “”)",
1504
+ "# “Demi(<>,15,7)”",
1505
+ "; “” ((d 123456789012345678901234567890) 987654321098765432109876543210)",
1506
+ "# “Demi(<>,123456789012345678901234567890,987654321098765432109876543210)”",
1507
+ "```",
1508
+ "A Frame without a Size is not deposited: its failure is the answer",
1509
+ "```",
1510
+ "; d ([].nope)",
1511
+ "# $!.name-missing “...",
1512
+ "; “” d",
1513
+ "# “Demi(<>,0,0)”",
1514
+ "```",
1515
+ "Deposit reads the receiver through `_^`, so an argument that holds fields of",
1516
+ "the same names deposits by its Size and nothing else",
1517
+ "```",
1518
+ "; “” (d [.left 50; .phase 1; .s 100; 4])",
1519
+ "# “Demi((),4,0)”",
1520
+ "```",
1521
+ "A Demi captured by a closure, mapped, or reduced is applied the same way, and",
1522
+ "the captured one stays as it was",
1523
+ "```",
1524
+ "; .start (Demi [2, 0, 0]); .step {start _};",
1525
+ "; [“” (step 5), “” (step 3), “” start]",
1526
+ "# [“Demi((),5,0)”, “Demi((),3,0)”, “Demi(<>,0,0)”]",
1527
+ "; [d, a] & {“” (_ 5)}",
1528
+ "# [“Demi((),5,0)”, “Demi((),10,3)”]",
1529
+ "; “” ([5, 3, 7] | (Demi [2, 0, 0]))",
1530
+ "# “Demi((),12,3)”",
1531
+ "```",
1532
+ "Through a mutable name, application writes the Demi in place",
1533
+ "```",
1534
+ "; .m_ (Demi [2, 0, 0]);",
1535
+ "; m_ 5;",
1536
+ "; “” m_",
1537
+ "# “Demi((),5,0)”",
1538
+ "```",
1539
+ "## Observers",
1540
+ "",
1541
+ "A Demi's Count is its phase, its Size the total load and its residual the",
1542
+ "signed difference, including a present zero-load Demi in either phase",
1543
+ "```",
1544
+ "; .e (Demi [1, 12, 3]);",
1545
+ "; [e.#, e.##, e.###]",
1546
+ "# [1, 15, 9]",
1547
+ "; [d.#, d.##, d.###, (Demi [1, 0, 0]).#]",
1548
+ "# [2, 0, 0, 1]",
1549
+ "```",
1550
+ "So its fourth hash is the same Demi, however often it is taken. It is equal,",
1551
+ "not identical: each observation builds a new instance",
1552
+ "```",
1553
+ "; [e.#### = e, e.#### === e, e.#### == e, ((e.####).####).#### = e]",
1554
+ "# [<>, (), <>, <>]",
1555
+ "; [d.#### = d, (Demi [1, 0, 0]).#### = (Demi [1, 0, 0])]",
1556
+ "# [<>, <>]",
1557
+ "```",
1558
+ "A Demi inside an aggregate contributes its declared Size",
1559
+ "```",
1560
+ "; [[e, e].##, [e, d].###, [e].#### = (Demi [1, 15, 0])]",
1561
+ "# [30, 15, <>]",
1562
+ "```",
1563
+ "## The fourth hash",
1564
+ "",
1565
+ "`.####` answers an instance of this class, built from the same source, so it",
1566
+ "compares equal to one built here",
1567
+ "```",
1568
+ "; [[5, 3].#### = (Demi [2, 5, 3]), “hello”.#### = (Demi [1, 3, 2]), [0].#### = (Demi [1, 0, 0])]",
1569
+ "# [<>, <>, <>]",
1570
+ "; “” [5, 3, 7].####",
1571
+ "# “Demi((),12,3)”",
1572
+ "```",
1573
+ "It is nil where there is no Demi: an empty host, Count zero, no Count, or no",
1574
+ "residual. Properties are not elements, sharing counts each occurrence, and a",
1575
+ "group observes as its elements",
1576
+ "```",
1577
+ "; [[].####, 0.####, ().####, <2,3,5>.####]",
1578
+ "# [(), (), (), ()]",
1579
+ "; .shared [1, 2];",
1580
+ "; [[.a 100; 5, 3].#### = [5, 3].####, [shared, shared].#### = (Demi [2, 3, 3]), (5, 3).#### = (Demi [2, 5, 3])]",
1581
+ "# [<>, <>, <>]",
1582
+ "```",
1583
+ "## Observing commutes with applying",
1584
+ "",
1585
+ "For a nonempty host X, observing X Y is applying X's Demi to Y, and both equal",
1586
+ "the observation of the array X Y constructs",
1587
+ "```",
1588
+ "; .X [5, “ab”, [1, 2]];",
1589
+ "; [(X 7).#### = (X.#### 7), (X 7).#### = [5, “ab”, [1, 2], 7].####, (X {5 + 3}).#### = (X.#### {5 + 3})]",
1590
+ "# [<>, <>, <>]",
1591
+ "```",
1592
+ "The empty host is the boundary. `[].####` is nil, a choice of convention",
1593
+ "(011.15g) rather than a theorem, and applying nil answers the argument, so",
1594
+ "the equation as written fails there. Lifting the empty host to the zero-load",
1595
+ "Demi in phase 2 restores it: that is the initialized-router reading, and it is",
1596
+ "also what a reduce starts from",
1597
+ "```",
1598
+ "; [([] 7).#### = ([].#### 7), ([] 7).#### = ((Demi [2, 0, 0]) 7), ([] 7).#### = ([7] | (Demi [2, 0, 0]))]",
1599
+ "# [(), <>, <>]",
1600
+ "; [] | (Demi [2, 0, 0]) = (Demi [2, 0, 0])",
1601
+ "# <>",
1602
+ "```",
1603
+ "## Scaling and Star",
1604
+ "",
1605
+ "Scaling multiplies both loads and keeps the phase: zero annihilates, one is",
1606
+ "the identity, and scaling composes",
1607
+ "```",
1608
+ "; [“” (e.scale_ 2), “” (e.scale_ 0), (e.scale_ 1) = e, ((e.scale_ 2).scale_ 3) = (e.scale_ 6)]",
1609
+ "# [“Demi((),24,6)”, “Demi((),0,0)”, <>, <>]",
1610
+ "; e.scale_ (0 - 2)",
1611
+ "# $!.name-missing “$:Frame.0.invalid-scale”;",
1612
+ "```",
1613
+ "It is the shadow of Star on a nonempty host",
1614
+ "```",
1615
+ "; [([5, 3] * 3).#### = ([5, 3].####.scale_ 3), ([[[]], []] * [[], []]).#### = ([[[]], []].####.scale_ ([[], []].##))]",
1616
+ "# [<>, <>]",
1617
+ "```",
1618
+ "No operator is overloaded: `+` is ordinary addition, which a Demi is not a",
1619
+ "number for, and `*` is ordinary Star, which refuses an aggregate with fields",
1620
+ "```",
1621
+ "; [e + 3, e * 3]",
1622
+ "# [(), $!.star-metadata *]",
1623
+ "```",
1624
+ "## A precise regression: a load read at the wrong depth",
1625
+ "",
1626
+ "Carets count lexically, so inside a branch `_^` is the method's own scope, not",
1627
+ "the receiver. Reading a load there fails, `$!.name-missing`. Before 011.20,",
1628
+ "`+` turned that failure into nil, and writing nil leaves a field as it was, so",
1629
+ "the deposit silently did nothing while the phase still flipped. Now the",
1630
+ "failure reaches the field, where it shows",
1631
+ "```",
1632
+ "; .Wrong {[.phase 2; .left 0; .apply_ {.s (_ .##); (_^.phase = 2) ? {@left (_^.left + s); @phase 1;};}]};",
1633
+ "; .w ((Wrong ()) 5);",
1634
+ "; [w.phase, w.left]",
1635
+ "# [1, $!.name-missing “...",
1636
+ "; .Right {[.phase 2; .left 0; .apply_ {.s (_ .##); (_^.phase = 2) ? {@left (_^^.left + s); @phase 1;};}]};",
1637
+ "; .r ((Right ()) 5);",
1638
+ "; [r.phase, r.left]",
1639
+ "# [1, 5]",
1640
+ "```",
1641
+ "## Importing",
1642
+ "",
1643
+ "Imported, the file binds the same class. The import is an example line, so",
1644
+ "the evaluator, which reads this file without a root, never runs it",
1645
+ "```",
1646
+ "; Demis <- './hc/demi.hc';",
1647
+ "; [(Demis.Demi [2, 5, 3]) = [5, 3].####, “” ((Demis.Demi [2, 0, 0]) 4)]",
1648
+ "# [<>, “Demi((),4,0)”]",
1649
+ "",
1650
+ ].join("\n"),
1651
+ ],
1162
1652
  [
1163
1653
  "hc/figures.hc",
1164
1654
  [
@@ -1186,9 +1676,15 @@ export const HC_SOURCES = new Map([
1186
1676
  "Flat repetition is `x.## [y]`. A tally, when wanted, is an explicit",
1187
1677
  "construction, such as `x & {[[]]}` for one fresh mark per immediate element.",
1188
1678
  "Native `.##` uses each child's native Size, including numeric magnitude and",
1189
- "text length. Native `.###` also accepts mixed arrays and evaluated groups.",
1679
+ "text length. Native `.###` also accepts mixed arrays, groups, and non-schema list syntax/closures. Every other",
1680
+ "value with a Count answers its parity (`.# mod 2`, a FrameInt), including valid zero, so equal quantities",
1681
+ "observe alike whatever their kind or numeric type; schemas answer nil. `()` has no Count; `<>` observes as `[]`.",
1682
+ "Missing Count rules fall back to Size, including sized atoms. Explicit Counts take precedence.",
1683
+ "Stored errors and failed child quantities propagate rather than acquiring a load.",
1190
1684
  "Star keeps its narrower array/Count composition domain.",
1191
1685
  "",
1686
+ "For Counts, Gap and Spin now use parity too: `gap 7` is 1 and `spin 2 4` is 0.",
1687
+ "",
1192
1688
  "Only two derived mathematical abbreviations remain: Gap = |signed residual|",
1193
1689
  "and Spin = signed residual / positive Count. They define no Figure domain.",
1194
1690
  "Incidence is native `point ~~~ line`; collective incidence uses ordinary",
@@ -1300,7 +1796,7 @@ export const HC_SOURCES = new Map([
1300
1796
  "; [[[], [[]]], [[[], []], []], [[[[], [], []]]]].###",
1301
1797
  "# 2",
1302
1798
  "; [[1, []].###, [[], “ab”].###, [[], ([], [])].###, 5.###]",
1303
- "# [0, -1, -1, ()]",
1799
+ "# [0, -1, -1, 1]",
1304
1800
  "```",
1305
1801
  "Native Size also measures mixed values, independently of structural Star.",
1306
1802
  "Numeric magnitude truncates exactly; text length uses native Unicode code-point iteration,",
@@ -1315,7 +1811,7 @@ export const HC_SOURCES = new Map([
1315
1811
  "; [[5, “hello”].##, [5, “hello”].###, (5, 3).###, [5, 3, 2, 7].###]",
1316
1812
  "# [10, 0, 2, -3]",
1317
1813
  "; [([5, “hello”].### ? {<>} : {()}), (5.### ? {<>} : {()})]",
1318
- "# [<>, ()]",
1814
+ "# [<>, <>]",
1319
1815
  "; { .x <[].<>> _; x.### } [[], [“nested atom”]]",
1320
1816
  "# -10",
1321
1817
  "```",
@@ -1359,6 +1855,48 @@ export const HC_SOURCES = new Map([
1359
1855
  "; [.tag 1;] * [[]]",
1360
1856
  "# $!.star-metadata *",
1361
1857
  "```",
1858
+ "The fourth observer derives a Demi from Count, Size and residual.",
1859
+ "A zero Count or absent residual gives no Demi; errors propagate. A schema used",
1860
+ "as an explicit element contributes Size normally, even though its own Demi is nil.",
1861
+ "A present Demi has Size L+R and residual L−R. Its Count is the least positive",
1862
+ "representative of its stored parity: 2 for all/even and 1 for nil/odd. The same",
1863
+ "universal derivation therefore reconstructs its data value on repeated fourth",
1864
+ "observation, including present zero loads, without a special fourth-hash rule.",
1865
+ "A present Demi is an instance of the HC class in `hc/demi.hc` (011.20), and",
1866
+ "reads as text `Demi(phase,left,right)`. Applying a Demi to Y deposits Y's Size",
1867
+ "and flips the phase, so for a nonempty Figure host X, (X Y).#### is",
1868
+ "X.#### Y; for an empty host, start from the zero-load Demi in phase 2 instead,",
1869
+ "because [].#### is nil. Scaling is the method `scale_`, the shadow of Star:",
1870
+ "(X * Y).#### is X.####.scale_ (Y.##) for a nonempty host. Count is a terminal",
1871
+ "quantity: positive Counts agree with pure Figures of that terminal Size, but 0",
1872
+ "has Size 0 while [] has Size 1. Mixed values may have present zero-load Demis,",
1873
+ "including [0].####.",
1874
+ "```",
1875
+ "; [[].####, 0.####, “” “hello”.####, <2,3,5>.####]",
1876
+ "# [(), (), “Demi((),3,2)”, ()]",
1877
+ "; [(10 - 5).#### = 5.####, (0 - 5).#### = 5.####, (5.0).#### = 5.####, “hello”.#### = 5.####]",
1878
+ "# [<>, <>, <>, <>]",
1879
+ "; [<>.#, <>.##, <>.###, ().##]",
1880
+ "# [0, 1, 0, 1]",
1881
+ "; [1, 2, 3, 7] & {“” _.####}",
1882
+ "# [“Demi((),1,0)”, “Demi(<>,1,1)”, “Demi((),2,1)”, “Demi((),4,3)”]",
1883
+ "; [[0], [“hello”], [<2,3,5>,2], {5 + 3}] & {“” _.####}",
1884
+ "# [“Demi((),0,0)”, “Demi((),5,0)”, “Demi(<>,3,2)”, “Demi((),8,1)”]",
1885
+ "; [“” ([[],[]].#### 3), “” (7.####.scale_ 2), ([[],[]] 3).#### = ([[],[]].#### 3)]",
1886
+ "# [“Demi((),4,1)”, “Demi((),8,6)”, <>]",
1887
+ "```",
1888
+ "A RotorRouter, the class in `hc/rotor-router.hc` (011.21), keeps the routed",
1889
+ "Figures themselves in two ordered channels and declares the observers that make",
1890
+ "its fourth hash their Demi. Routing a Figure's children in turn from the initial",
1891
+ "router sends the even positions left and the odd ones right, and that router's",
1892
+ "fourth hash is the Figure's.",
1893
+ "```",
1894
+ "; Routers <- './hc/rotor-router.hc';",
1895
+ "; .fr ([[], [[], []], []] | (Routers.RotorRouter [2, [], []]));",
1896
+ "; [fr.left, fr.right, fr.#### = [[], [[], []], []].####]",
1897
+ "# [[[], []], [[[], []]], <>]",
1898
+ "",
1899
+ "```",
1362
1900
  "Importing skips the examples and ends on a native true value.",
1363
1901
  "```",
1364
1902
  "[] = []",
@@ -1974,6 +2512,373 @@ export const HC_SOURCES = new Map([
1974
2512
  "",
1975
2513
  ].join("\n"),
1976
2514
  ],
2515
+ [
2516
+ "hc/rotor-router.hc",
2517
+ [
2518
+ "#!/usr/bin/env hc",
2519
+ "```",
2520
+ "RotorRouter (occurrence/figure 011.21)",
2521
+ "",
2522
+ "A RotorRouter is a two-channel router that keeps what it routes. It holds a",
2523
+ "phase and two ordered arrays, left and right, of the Frames routed into them.",
2524
+ "Applying a router to a Frame appends that Frame, the same Frame, to the active",
2525
+ "channel and flips the phase. A Demi follows the same alternation by Size alone;",
2526
+ "a router keeps the children, so its numerical shadow is a Demi and its state is",
2527
+ "everything that shadow forgets: which Frames, in what order, and which channel.",
2528
+ "",
2529
+ "`RotorRouter` is an ordinary HC class, like `Demi` in `hc/demi.hc`: a",
2530
+ "constructor closure answering a fresh aggregate whose fields are its state and",
2531
+ "whose methods are the class. Import it with",
2532
+ "`Routers <- './hc/rotor-router.hc'`, then `Routers.RotorRouter [2, [], []]`.",
2533
+ "",
2534
+ "**State.** `RotorRouter [phase, left, right]` takes a Count phase and two",
2535
+ "arrays. The phase is the state of the next route, encoded as a Demi's is:",
2536
+ "2 when left is next and 1 when right is next. A channel is its elements: an",
2537
+ "array's properties are configuration, not routed Frames, so the constructor",
2538
+ "keeps the elements in a fresh array of its own, and a channel argument that",
2539
+ "declares `apply` cannot change what appending means. Anything else is refused",
2540
+ "with `invalid-router`, a missing name, as `Demi` refuses with `invalid-demi`.",
2541
+ "Any phase and any two channels are a state; nothing requires the channels to",
2542
+ "be a history the router could have produced.",
2543
+ "",
2544
+ "**Routing**, `router x`: append x as one member of the active channel and flip",
2545
+ "the phase. Routing never evaluates x, never measures it, and never runs its",
2546
+ "methods, so a closure is kept uncalled, an array or group is kept as one",
2547
+ "member, and a Frame whose Size fails or runs code is routed like any other. A",
2548
+ "Frame of Size zero still takes a slot and flips the phase. It is a mutating",
2549
+ "method, `apply_`, so through a name it is a functional update that leaves the",
2550
+ "router as it was, and through a mutable name it writes the router in place.",
2551
+ "Routing nil routes nothing and leaves the router as it was, as applying a Demi",
2552
+ "to nil does. A flagged error such as `1 / 0` is the answer of the expression",
2553
+ "that applies the router, so it is never routed.",
2554
+ "",
2555
+ "**Observers.** A router declares its Count, Size and residual as a Demi does:",
2556
+ "its phase, its total load L+R and the signed difference L−R, where each load is",
2557
+ "the sum of the Sizes of the children routed into that channel. So `router.####`",
2558
+ "derives the router's Demi as it derives any Frame's, and that Demi is the",
2559
+ "router's numerical shadow. An empty channel has load 0, the empty sum; a",
2560
+ "nonempty channel's load is its native Size, which is that sum. Observation is",
2561
+ "where children are measured, so it is where their failures show, and declared",
2562
+ "observers run only when the router is observed: routing runs none of them, and",
2563
+ "observing writes nothing. The Demi forgets which Frames were routed and their",
2564
+ "order, so distinct routers can share one.",
2565
+ "",
2566
+ "**Text.** A router prints as its fields and methods, and as text reads",
2567
+ "`RotorRouter(<>,[…],[…])`, with the phase spelled as the orientation it stands",
2568
+ "for and each channel as its spelling.",
2569
+ "",
2570
+ "**Methods read their own state through `_^`.** A router is applied to",
2571
+ "arbitrary Frames, and a bare name in a method is looked up on the argument",
2572
+ "first (spec 7), so a router reads its fields through the receiver, `_^` from",
2573
+ "the method body. What a branch needs is bound as a local at method level.",
2574
+ "```",
2575
+ ".channel-load {.c _; (c.# = 0) ? {0} : {c.##}};",
2576
+ ".RotorRouter {.p (_ .0); .l (_ .1); .r (_ .2);",
2577
+ " ((((p = 2) : {p = 1}) ? {p ~ (0.<>)}) ? {(l ~ ([].<>)) ? {r ~ ([].<>)}}) ? {[",
2578
+ " .phase p;",
2579
+ " .left (l | []);",
2580
+ " .right (r | []);",
2581
+ " .apply_ {.x _; .l (_^ .left); .r (_^ .right);",
2582
+ " ((_^ .phase) = 2) ? {@left (l x); @phase 1;} : {@right (r x); @phase 2;};};",
2583
+ " .# {_^.phase};",
2584
+ " .## {(channel-load (_^ .left)) + (channel-load (_^ .right))};",
2585
+ " .### {(channel-load (_^ .left)) - (channel-load (_^ .right))};",
2586
+ " .toText {“RotorRouter(” (((_^ .phase) = 2) ? {“<>”} : {“()”}) “,” (_^ .left) “,” (_^ .right) “)”}",
2587
+ " ]} : {invalid-router}};",
2588
+ "```",
2589
+ "## Construction",
2590
+ "",
2591
+ "A router holds exactly its phase and its two channels. The initial router is",
2592
+ "present, phase 2 with both channels empty",
2593
+ "```",
2594
+ "; .r0 (RotorRouter [2, [], []]);",
2595
+ "; [r0.phase, r0.left, r0.right, “” r0]",
2596
+ "# [2, [], [], “RotorRouter(<>,[],[])”]",
2597
+ "```",
2598
+ "Anything but a phase of 1 or 2 and two arrays is refused",
2599
+ "```",
2600
+ "; RotorRouter [3, [], []]",
2601
+ "# $!.name-missing “$:Frame.0.invalid-router”;",
2602
+ "; [RotorRouter [(5 - 3), [], []], RotorRouter [2, [], 5], RotorRouter [2, (1, 2), []], RotorRouter [2, []], RotorRouter 5]",
2603
+ "# [$!.name-missing “$:Frame.0.invalid-router”;, $!.name-missing “$:Frame.0.invalid-router”;, $!.name-missing “$:Frame.0.invalid-router”;, $!.name-missing “$:Frame.0.invalid-router”;, $!.name-missing “$:Frame.0.invalid-router”;]",
2604
+ "```",
2605
+ "A channel is its elements. The router keeps them in an array of its own, so a",
2606
+ "channel's properties and a declared `apply` do not come with it",
2607
+ "```",
2608
+ "; .Hijack [.apply {“hijack”}; 1];",
2609
+ "; [(RotorRouter [2, [.tag 9; 5], []]).left, ((RotorRouter [2, Hijack, []]) 7).left]",
2610
+ "# [[5], [1, 7]]",
2611
+ "```",
2612
+ "## Routing alternates",
2613
+ "",
2614
+ "From the initial router, routing A, B and C sends A and C left and B right,",
2615
+ "and the next route goes right",
2616
+ "```",
2617
+ "; .A [1, [2]]; .B “b”; .C {5 + 3};",
2618
+ "; .r3 (((r0 A) B) C);",
2619
+ "; [r3.phase, r3.left, r3.right]",
2620
+ "# [1, [[1, [2]], { 5 + 3 }], [“b”]]",
2621
+ "; “” r3",
2622
+ "# “RotorRouter((),[[1, [2]], { 5 + 3 }],[“b”])”",
2623
+ "```",
2624
+ "The router that was routed into is left as it was",
2625
+ "```",
2626
+ "; [r0.phase, r0.left, r0.right]",
2627
+ "# [2, [], []]",
2628
+ "```",
2629
+ "## Routing keeps the Frame",
2630
+ "",
2631
+ "A channel member is the routed Frame itself. An array or a group is routed as",
2632
+ "one member, never spread into its elements, and a closure is kept, not called.",
2633
+ "Iterating a channel yields its members as they are. Reading a closure by dot",
2634
+ "from an aggregate, `r3.left.1`, answers a method bound to that aggregate,",
2635
+ "which is the general rule for methods and not the router's, so the closure's",
2636
+ "identity is seen by iterating",
2637
+ "```",
2638
+ "; [r3.left.0 === A, r3.right.0 === B, r3.left & {_ === C}]",
2639
+ "# [<>, <>, [(), <>]]",
2640
+ "; [(r0 [1, 2]).left, (r0 (4, 5)).left, (r0 {5 + 3}).left, (r0 []).left]",
2641
+ "# [[[1, 2]], [(4, 5)], [{ 5 + 3 }], [[]]]",
2642
+ "```",
2643
+ "A Frame held through a mutable name is the same Frame in the channel, so a",
2644
+ "write through that name shows there. A write reached through an immutable",
2645
+ "router is a functional update, as it is everywhere, so it changes neither",
2646
+ "```",
2647
+ "; .kid_ [.n 1; .set_ {@n _;}];",
2648
+ "; .rk (r0 kid_);",
2649
+ "; kid_.set_ 5;",
2650
+ "; [rk.left.0 === kid_, rk.left.0.n]",
2651
+ "# [<>, 5]",
2652
+ "; [(rk.left.0.set_ 9).n, kid_.n, rk.left.0.n]",
2653
+ "# [9, 5, 5]",
2654
+ "```",
2655
+ "## Independent states",
2656
+ "",
2657
+ "Any phase and channels construct a router, here phase 1 with a preloaded",
2658
+ "left channel. Routing continues from that state",
2659
+ "```",
2660
+ "; .p1 (RotorRouter [1, [A], []]);",
2661
+ "; .p2 ((p1 B) C);",
2662
+ "; [p2.phase, p2.left, p2.right, p1.phase, p1.right]",
2663
+ "# [1, [[1, [2]], { 5 + 3 }], [“b”], 1, []]",
2664
+ "```",
2665
+ "Routers built from the same channel share no writable state: each holds its",
2666
+ "own channel array. Through a mutable name, routing writes that router in place",
2667
+ "and no other",
2668
+ "```",
2669
+ "; .ch [A];",
2670
+ "; .u (RotorRouter [2, ch, []]); .v (RotorRouter [2, ch, []]);",
2671
+ "; .m_ (RotorRouter [2, ch, []]);",
2672
+ "; m_ B;",
2673
+ "; m_ C;",
2674
+ "; [m_.phase, m_.left, m_.right, u.left, v.left, ch]",
2675
+ "# [2, [[1, [2]], “b”], [{ 5 + 3 }], [[1, [2]]], [[1, [2]]], [[1, [2]]]]",
2676
+ "; [u.left === ch, u.left === v.left, u.left.0 === v.left.0]",
2677
+ "# [(), (), <>]",
2678
+ "```",
2679
+ "A router captured by a closure, mapped, or reduced into routes the same way,",
2680
+ "and the captured one stays as it was",
2681
+ "```",
2682
+ "; .start (RotorRouter [2, [], []]); .step {start _};",
2683
+ "; [(step 5).left, (step 3).left, start.left]",
2684
+ "# [[5], [3], []]",
2685
+ "; [r0, p1] & {(_ 5).right}",
2686
+ "# [[], [5]]",
2687
+ "; “” ([A, B, C] | r0)",
2688
+ "# “RotorRouter((),[[1, [2]], { 5 + 3 }],[“b”])”",
2689
+ "```",
2690
+ "## Routing measures nothing",
2691
+ "",
2692
+ "Routing does not observe the Frame it routes. A Frame whose Size fails, one",
2693
+ "whose Size is cyclic, and one whose Size runs code that counts are routed",
2694
+ "like any other, and nothing ran",
2695
+ "```",
2696
+ "; .counter_ [.n 0; .inc_ {@n (_^.n + 1);}];",
2697
+ "; .Counted [.## {counter_.inc_ (); 5}; 1];",
2698
+ "; .Failing [.## {[].nope}; 1];",
2699
+ "; .Cyclic [.## {_^.##}];",
2700
+ "; .rf ((((r0 Counted) Failing) Cyclic) Counted);",
2701
+ "; [rf.phase, rf.left.#, rf.right.#, counter_.n]",
2702
+ "# [2, 2, 2, 0]",
2703
+ "```",
2704
+ "Observing the router is where they are measured, so it is where they fail and",
2705
+ "where the counting code runs. The fourth hash reads the router's Size and its",
2706
+ "residual, and each measures both channels, so a child's Size is read twice",
2707
+ "```",
2708
+ "; (r0 Failing).####",
2709
+ "# $!.name-missing “...",
2710
+ "; (r0 Cyclic).####",
2711
+ "# $!.cyclic-observation .##",
2712
+ "; “” ((r0 Counted).####)",
2713
+ "# “Demi((),5,0)”",
2714
+ "; counter_.n",
2715
+ "# 2",
2716
+ "```",
2717
+ "A flagged error is the answer of the expression that applies the router, so it",
2718
+ "is never routed. A diagnostic note such as a missing name is a value and is",
2719
+ "routed like one, until #467 decides otherwise, and observing it fails",
2720
+ "```",
2721
+ "; r0 (1 / 0)",
2722
+ "# $!.division-by-zero /",
2723
+ "; .noted (r0 ([].nope));",
2724
+ "; [noted.phase, noted.left.#]",
2725
+ "# [1, 1]",
2726
+ "; noted.####",
2727
+ "# $!.name-missing “...",
2728
+ "```",
2729
+ "Routing nil routes nothing",
2730
+ "```",
2731
+ "; [(r0 ()).phase, (r0 ()).left]",
2732
+ "# [2, []]",
2733
+ "```",
2734
+ "## Empty and zero",
2735
+ "",
2736
+ "The initial router observes as the present zero-load Demi in phase 2. That is",
2737
+ "the router's state, and it leaves the fourth hash's convention alone: the",
2738
+ "empty host still has no Demi",
2739
+ "```",
2740
+ "; [“” (r0.####), (r0.####) = [0, 0].####, [].####]",
2741
+ "# [“Demi(<>,0,0)”, <>, ()]",
2742
+ "```",
2743
+ "A Frame of Size zero takes a slot and flips the phase, and an empty array",
2744
+ "routed as a child has Size 1, while an empty channel has load 0",
2745
+ "```",
2746
+ "; .z (r0 0);",
2747
+ "; [z.phase, z.left, “” (z.####)]",
2748
+ "# [1, [0], “Demi((),0,0)”]",
2749
+ "; [“” ((r0 []).####), “” (((r0 []) []).####), “” ((((r0 0) 0) 0).####)]",
2750
+ "# [“Demi((),1,0)”, “Demi(<>,1,1)”, “Demi((),0,0)”]",
2751
+ "```",
2752
+ "## The router's Demi",
2753
+ "",
2754
+ "Each load is the sum of its channel's child Sizes, as exact Counts, over text,",
2755
+ "numbers, nested arrays, groups, closures, all, and a Frame routed twice, which",
2756
+ "counts each time it was routed",
2757
+ "```",
2758
+ "; .shared [[], []];",
2759
+ "; .mix ((((((((r0 “hello”) 7) [[1, 2], [3]]) (4, 5)) shared) shared) {5 + 3}) <>);",
2760
+ "; [mix.left, mix.right]",
2761
+ "# [[“hello”, [[1, 2], [3]], [[], []], { 5 + 3 }], [7, (4, 5), [[], []], <>]]",
2762
+ "; [mix.left & {_.##}, mix.right & {_.##}, “” (mix.####)]",
2763
+ "# [[5, 6, 2, 9], [7, 9, 2, 1], “Demi(<>,22,19)”]",
2764
+ "; “” (((r0 123456789012345678901234567890) 987654321098765432109876543210).####)",
2765
+ "# “Demi(<>,123456789012345678901234567890,987654321098765432109876543210)”",
2766
+ "```",
2767
+ "## Observing commutes with routing",
2768
+ "",
2769
+ "Routing each child of an array X in turn, from the initial router, is the",
2770
+ "reduce `X | r0`. Its left channel holds the children at even positions and its",
2771
+ "right channel those at odd positions, and its phase is the parity of X's Count.",
2772
+ "That interleaving is the invariant a router reached this way keeps: left has",
2773
+ "as many children as right in phase 2, and one more in phase 1",
2774
+ "```",
2775
+ "; .X [5, “ab”, [1, 2]];",
2776
+ "; .rx (X | r0);",
2777
+ "; [rx.left, rx.right, rx.phase, rx = (RotorRouter [1, [5, [1, 2]], [“ab”]])]",
2778
+ "# [[5, [1, 2]], [“ab”], 1, <>]",
2779
+ "```",
2780
+ "For such a router its fourth hash is X's, and routing Y then observing is",
2781
+ "observing X Y. The state-level law holds for every router: observing after a",
2782
+ "route is applying the router's Demi to the routed Frame",
2783
+ "```",
2784
+ "; .Y [[], [], []];",
2785
+ "; [(rx.####) = X.####, ((rx Y).####) = (X Y).####, ((rx Y).####) = ((rx.####) Y)]",
2786
+ "# [<>, <>, <>]",
2787
+ "; [((p1 Y).####) = ((p1.####) Y), ((p2 {5 + 3}).####) = ((p2.####) {5 + 3}), ((r0 0).####) = ((r0.####) 0)]",
2788
+ "# [<>, <>, <>]",
2789
+ "```",
2790
+ "The empty host is the boundary. `[].####` is nil, so `X.####` fails the first",
2791
+ "equation when X is empty, while the initial router observes as a present Demi.",
2792
+ "The router is the empty host lifted: routing nothing from it leaves it as it",
2793
+ "is, and after one route the two agree again",
2794
+ "```",
2795
+ "; [([] | r0) = r0, (([] | r0).####) = [].####, (([Y] | r0).####) = ([] Y).####]",
2796
+ "# [<>, (), <>]",
2797
+ "```",
2798
+ "The equation with the fourth hash needs the interleaving. A preloaded router",
2799
+ "can break it: one child left and none right in phase 2 is a state no array's",
2800
+ "routing reaches, yet its fourth hash equals that of an array whose",
2801
+ "history is different",
2802
+ "```",
2803
+ "; .pre (RotorRouter [2, [A], []]);",
2804
+ "; [(pre.####) = [A, 0].####, ([A, 0] | r0) = pre]",
2805
+ "# [<>, ()]",
2806
+ "```",
2807
+ "## The Demi forgets",
2808
+ "",
2809
+ "Distinct routers can share a Demi: the fourth hash keeps only the",
2810
+ "phase and two sums, not which Frames were routed, nor their order, nor how",
2811
+ "the load was split among them",
2812
+ "```",
2813
+ "; .s1 (RotorRouter [2, [2, 3], [1]]); .s2 (RotorRouter [2, [5], [1]]); .s3 (RotorRouter [2, [3, 2], [1]]);",
2814
+ "; [s1 = s2, s1 = s3, (s1.####) = (s2.####), (s1.####) = (s3.####)]",
2815
+ "# [(), (), <>, <>]",
2816
+ "```",
2817
+ "## Observers, declared",
2818
+ "",
2819
+ "A router's Count, Size and residual are its Demi's, and its fourth hash is a",
2820
+ "Demi, not the router: equal, it would have to be the same class. Its channels",
2821
+ "are fields, not elements, so iterating a router yields nothing. A router",
2822
+ "inside an aggregate contributes its declared Size, as a Demi does",
2823
+ "```",
2824
+ "; [[r3.#, r3.##, r3.###] = [r3.####.#, r3.####.##, r3.####.###], r3.#### = r3, r3.####.#### = r3.####]",
2825
+ "# [<>, (), <>]",
2826
+ "; [r3 & {_}, [r3, r3].##, [r3].#### = [13].####]",
2827
+ "# [[], 26, <>]",
2828
+ "```",
2829
+ "Observing a router runs its declared observers and nothing else. It routes",
2830
+ "nothing and writes nothing, so the router is as it was",
2831
+ "```",
2832
+ "; .seen (((r0 A) B) C);",
2833
+ "; seen.####;",
2834
+ "; [seen = r3, seen.phase, seen.left.#, seen.right.#]",
2835
+ "# [<>, 1, 2, 1]",
2836
+ "```",
2837
+ "## Reading the receiver",
2838
+ "",
2839
+ "An argument whose fields share the router's names, or its locals', is routed",
2840
+ "as one member, and the router reads only its own fields",
2841
+ "```",
2842
+ "; .masked (r0 [.phase 1; .left [8]; .x 9; .l [7]; 4]);",
2843
+ "; [masked.phase, masked.left.#, masked.left.0.x, masked.right]",
2844
+ "# [1, 1, 9, []]",
2845
+ "```",
2846
+ "Carets count lexically (spec a06). Inside a branch, `_^` is the method's own",
2847
+ "scope, so a router that reads its channel there reads nothing, and the failure",
2848
+ "is written to the field. `_^^` is the receiver from inside the branch",
2849
+ "```",
2850
+ "; .WrongRouter {[.phase 2; .left []; .apply_ {.x _; ((_^ .phase) = 2) ? {@left (_^ .left x); @phase 1;};}]};",
2851
+ "; .w ((WrongRouter ()) 5);",
2852
+ "; [w.phase, w.left]",
2853
+ "# [1, $!.name-missing “...",
2854
+ "; .RightRouter {[.phase 2; .left []; .apply_ {.x _; ((_^ .phase) = 2) ? {@left (_^^ .left x); @phase 1;};}]};",
2855
+ "; .rr ((RightRouter ()) 5);",
2856
+ "; [rr.phase, rr.left]",
2857
+ "# [1, [5]]",
2858
+ "```",
2859
+ "## Text and spelling",
2860
+ "",
2861
+ "A router prints as the aggregate it is, and that spelling, written back as",
2862
+ "source, is an equal router. Its declared observers are spelled `.#`, `.##` and",
2863
+ "`.###`, which an expectation line, itself a `#…#` comment, cannot hold, so the",
2864
+ "printed form is matched here by its beginning",
2865
+ "```",
2866
+ "; RotorRouter [1, [5], []]",
2867
+ "# [.phase 1; .left [5]; .right []; .apply_ {...",
2868
+ "; (RotorRouter [1, [5], []]) = [.phase 1; .left [5]; .right []; .apply_ { .x _; .l (_^ .left); .r (_^ .right); ((_^ .phase) = 2) ? { @left (l x); @phase 1; } : { @right (r x); @phase 2; }; }; .# { _^ .phase }; .## { (channel-load (_^ .left)) + (channel-load (_^ .right)) }; .### { (channel-load (_^ .left)) - (channel-load (_^ .right)) }; .toText { “RotorRouter(” (((_^ .phase) = 2) ? { “<>” } : { “()” }) “,” (_^ .left) “,” (_^ .right) “)” };]",
2869
+ "# <>",
2870
+ "```",
2871
+ "## Importing",
2872
+ "",
2873
+ "Imported, the file binds the same class. The import is an example line, so",
2874
+ "importing this file does not import it again",
2875
+ "```",
2876
+ "; Routers <- './hc/rotor-router.hc';",
2877
+ "; [(Routers.RotorRouter [2, [], []]) = r0, “” ((Routers.RotorRouter [2, [], []]) 4), (((Routers.RotorRouter [2, [], []]) 4).####) = [4].####]",
2878
+ "# [<>, “RotorRouter((),[4],[])”, <>]",
2879
+ "",
2880
+ ].join("\n"),
2881
+ ],
1977
2882
  [
1978
2883
  "hc/testdoc.hc",
1979
2884
  [