hclang 0.38.0 → 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.
@@ -1075,6 +1075,14 @@ export const HC_SOURCES = new Map([
1075
1075
  "; Pt.peek [.n 7]",
1076
1076
  "# [7, 1]",
1077
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
+ "",
1078
1086
  "`A functional copy is its own receiver, so its methods read the fields the copy",
1079
1087
  "holds rather than those of the value it was copied from.`",
1080
1088
  "; .Tally [.n 1; .read {_^.n}; .bump_ {@n (_^.n + 1);}];",
@@ -1098,6 +1106,219 @@ export const HC_SOURCES = new Map([
1098
1106
  "",
1099
1107
  ].join("\n"),
1100
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
+ ],
1101
1322
  [
1102
1323
  "hc/cqml.hc",
1103
1324
  [
@@ -1663,6 +1884,17 @@ export const HC_SOURCES = new Map([
1663
1884
  "# [“Demi((),0,0)”, “Demi((),5,0)”, “Demi(<>,3,2)”, “Demi((),8,1)”]",
1664
1885
  "; [“” ([[],[]].#### 3), “” (7.####.scale_ 2), ([[],[]] 3).#### = ([[],[]].#### 3)]",
1665
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
+ "# [[[], []], [[[], []]], <>]",
1666
1898
  "",
1667
1899
  "```",
1668
1900
  "Importing skips the examples and ends on a native true value.",
@@ -2280,6 +2512,373 @@ export const HC_SOURCES = new Map([
2280
2512
  "",
2281
2513
  ].join("\n"),
2282
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
+ ],
2283
2882
  [
2284
2883
  "hc/testdoc.hc",
2285
2884
  [
@@ -219,7 +219,7 @@ export class FrameArray extends FrameList {
219
219
  return replaced;
220
220
  }
221
221
  lookup_here(key, origin) {
222
- if (/^\d+$/.test(key)) {
222
+ if (Frame.isIndexKey(key)) {
223
223
  return this.at(Number(key));
224
224
  }
225
225
  return super.lookup_here(key, origin);
@@ -152,8 +152,14 @@ export class FrameHandle extends Frame {
152
152
  links.push(this.target.parent);
153
153
  return links;
154
154
  }
155
+ /**
156
+ * A closure found under a field is a method of the target, so it answers
157
+ * bound to it. One found under an element index is data the target holds,
158
+ * so it answers as itself, as it does when read from a literal or by
159
+ * iteration: `xs.0 === C` holds for `.xs [C]`.
160
+ */
155
161
  lookup_result(value, key) {
156
- if (value.isClosure()) {
162
+ if (value.isClosure() && !Frame.isIndexKey(key)) {
157
163
  const effect = methodEffect(key);
158
164
  if (effect.mutating && this.mutable)
159
165
  this.copyOnWriteTarget();
@@ -21,6 +21,14 @@ export class MetaFrame {
21
21
  static isInteger(value) {
22
22
  return /^\p{N}+$/u.test(value);
23
23
  }
24
+ /**
25
+ * Whether a key addresses an element by index rather than naming a field.
26
+ * An aggregate reads such a key as a position, so `xs.0` is its first
27
+ * element, and an element is data, never a method of the aggregate.
28
+ */
29
+ static isIndexKey(key) {
30
+ return /^\d+$/.test(key);
31
+ }
24
32
  /**
25
33
  * Checks if the given character is alphabetic.
26
34
  *
@@ -1 +1 @@
1
- export const VERSION = "0.38.0";
1
+ export const VERSION = "0.38.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.38.0",
3
+ "version": "0.38.1",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",