hclang 0.43.0 → 0.44.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.
- package/esm/cli/hc.js +4 -1
- package/esm/lib/bundle/hc-sources.js +1096 -27
- package/esm/lib/execute/demi-prologue.js +19 -7
- package/esm/lib/execute/hc-eval.js +2 -0
- package/esm/lib/execute/router-prologue.js +153 -0
- package/esm/lib/frames/access-footprint.js +665 -0
- package/esm/lib/frames/bound-method.js +38 -0
- package/esm/lib/frames/dispatch-host.js +118 -0
- package/esm/lib/frames/effect-registry.js +21 -2
- package/esm/lib/frames/event-dispatch.js +192 -0
- package/esm/lib/frames/fourth-hash.js +88 -15
- package/esm/lib/frames/frame-array.js +41 -10
- package/esm/lib/frames/frame-expr.js +37 -6
- package/esm/lib/frames/frame-lazy.js +36 -4
- package/esm/lib/frames/frame-list.js +9 -2
- package/esm/lib/frames/frame-symbol.js +27 -0
- package/esm/lib/frames/frame.js +45 -6
- package/esm/lib/frames/reference-tracking.js +275 -0
- package/esm/lib/frames.js +7 -1
- package/esm/lib/ops/math.js +47 -1
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -887,6 +887,475 @@ export const HC_SOURCES = new Map([
|
|
|
887
887
|
"",
|
|
888
888
|
].join("\n"),
|
|
889
889
|
],
|
|
890
|
+
[
|
|
891
|
+
"hc/art-dispatch-vact.hc",
|
|
892
|
+
[
|
|
893
|
+
"#!/usr/bin/env hc",
|
|
894
|
+
"```",
|
|
895
|
+
"ART dispatch soundness: VACT witness for the footprint policy (occurrence/figure 015.24j, 015.24l)",
|
|
896
|
+
"",
|
|
897
|
+
"Construction → specified observation → vacted fact → interpretation.",
|
|
898
|
+
"Run from the repository root: `deno task hc hc/art-dispatch-vact.hc -t`.",
|
|
899
|
+
"",
|
|
900
|
+
"This testdoc constructs HC state and closures in ordinary file scope, hands",
|
|
901
|
+
"them to the dispatcher under test through the host bridge `$$.dispatch`, and",
|
|
902
|
+
"asserts what each policy does to them. The dispatcher is the library's own",
|
|
903
|
+
"(`lib/frames/event-dispatch.ts`); the bridge only turns an array of closures",
|
|
904
|
+
"into events and prints the report. `lib/frames/event-dispatch.vact.test.ts`",
|
|
905
|
+
"reads this file, re-runs it, and dispatches the same construction from the",
|
|
906
|
+
"host side with the finer observers (versions, certificates, refusals).",
|
|
907
|
+
"",
|
|
908
|
+
"The fragment. An event is one call of a closure written here, with nil as its",
|
|
909
|
+
"argument unless a pair `[closure, argument]` is given. The unit of",
|
|
910
|
+
"interleaving is the statement: a `;`-separated step of a sequenced body; a",
|
|
911
|
+
"nested call, and every arrow callback a commit fires, is inside its",
|
|
912
|
+
"statement. The observable of a dispatch is the tuple of the events' results,",
|
|
913
|
+
"in program order, failures included, followed by the state observer read",
|
|
914
|
+
"afterwards from the same scope (`state ()`, or the scenario's own). An arrow",
|
|
915
|
+
"callback is observed by what it does: the ones here count their firings in",
|
|
916
|
+
"shared state. The `trace`, `waited` and `escapes` properties record the",
|
|
917
|
+
"schedule the policy chose; they are instrumentation, not part of the",
|
|
918
|
+
"observable the claim is about.",
|
|
919
|
+
"",
|
|
920
|
+
"The claim the witnesses bear on (spec a12 §Soundness): every `footprint`",
|
|
921
|
+
"dispatch is observably equal to the `certified-sequential` run of the same",
|
|
922
|
+
"events, which runs them alone in program order, each under the certificate",
|
|
923
|
+
"inferred when it starts, so that an event whose actual access leaves its",
|
|
924
|
+
"certificate stops there, refused, keeping what it committed before (its",
|
|
925
|
+
"certified prefix). Where nothing is refused that run is the `sequential`",
|
|
926
|
+
"one. The `interleave` policy is the uncoordinated counterexample. The claim",
|
|
927
|
+
"is conditional on the events staying inside the fragment the guard sees: a",
|
|
928
|
+
"host native that reads state without a seam is outside it, and the",
|
|
929
|
+
"companion test exhibits that boundary.",
|
|
930
|
+
"",
|
|
931
|
+
"Arrow callbacks registered here persist, as every registration does, so",
|
|
932
|
+
"each arrow scenario re-arms a fresh managed value first (`rearm ()`).",
|
|
933
|
+
"",
|
|
934
|
+
"Construction: two mutable identities, aliases of x, and the closures.",
|
|
935
|
+
"```",
|
|
936
|
+
"; .x_ [.n 5; .set_ {@n _;}];",
|
|
937
|
+
"; .y_ [.n 10; .set_ {@n _;}];",
|
|
938
|
+
"; .y-of-x_ x_;",
|
|
939
|
+
"; .z x_;",
|
|
940
|
+
"; .t_ x_;",
|
|
941
|
+
"; .incr-x {.a x_.n; x_.set_ (a + 1); x_.n};",
|
|
942
|
+
"; .incr-y {.a y_.n; y_.set_ (a + 1); y_.n};",
|
|
943
|
+
"; .read-x {x_.n};",
|
|
944
|
+
"; .via-alias {.a y-of-x_.n; y-of-x_.set_ (a + 1); y-of-x_.n};",
|
|
945
|
+
"; .functional {(z.set_ 0).n};",
|
|
946
|
+
"; .move {.v x_.n; x_.set_ (v - 1); y_.set_ (y_.n + 1); x_.n + y_.n};",
|
|
947
|
+
"; .sum-slow {.a x_.n; .pad 0; a + y_.n};",
|
|
948
|
+
"; .retarget {@t_ y_; t_.n};",
|
|
949
|
+
"; .via-t {.a t_.n; t_.set_ (a + 1); t_.n};",
|
|
950
|
+
"; .mk {incr-x};",
|
|
951
|
+
"; .via-mk {(mk ()) ()};",
|
|
952
|
+
"; .getters [read-x];",
|
|
953
|
+
"; .setters [{x_.set_ _; x_.n}];",
|
|
954
|
+
"; .hidden-incr-x {.a (getters & {_ ()}); (setters & {_ ((a .0) + 1)}) .0};",
|
|
955
|
+
"; .each {_ & {_ ()}};",
|
|
956
|
+
"; .hidden-write-x {.a x_.n; (setters & {_ (a + 1)}) .0};",
|
|
957
|
+
"; .log_ [.count 0; .tick_ {@count (count + 1);}; .set-count_ {@count _;}];",
|
|
958
|
+
"; .cell_ [.v 1; .put_ {@v _;}];",
|
|
959
|
+
"; cell_ -> {log_.tick_ ()};",
|
|
960
|
+
"; .cell-twice {cell_.put_ 1; cell_.put_ 2; cell_.v};",
|
|
961
|
+
"; .log-slow {.c log_.count; log_.set-count_ (c + 10); log_.count};",
|
|
962
|
+
"; .ghost {Nothing <- './nothing.hc'; x_.set_ 0;};",
|
|
963
|
+
"; .reset {x_.set_ 5; y_.set_ 10; @t_ x_;};",
|
|
964
|
+
"; .state {[x_.n, y_.n]};",
|
|
965
|
+
"; .ygetters [{y_.n}];",
|
|
966
|
+
"; .prefix-x {x_.set_ 6; .b (ygetters & {_ ()}); b .0};",
|
|
967
|
+
"; .fired_ [.n 0; .tick_ {@n (n + 1);}; .set_ {@n _;}];",
|
|
968
|
+
"; .w_ [.n 0; .set_ {@n _;}];",
|
|
969
|
+
"; .armers [{w_ -> {fired_.tick_ ()}}];",
|
|
970
|
+
"; .arm-hidden {.p 0; (armers & {_ ()}) .0; fired_.n};",
|
|
971
|
+
"; .arm {.w w_; w -> {fired_.tick_ ()}; fired_.n};",
|
|
972
|
+
"; .poke {w_.set_ 1; fired_.n};",
|
|
973
|
+
"; .poke-late {.p 0; w_.set_ 1; fired_.n};",
|
|
974
|
+
"; .rearm {@w_ [.n 0; .set_ {@n _;}]; fired_.set_ 0;};",
|
|
975
|
+
"; .watch {[w_.n, fired_.n]};",
|
|
976
|
+
"; .cell2_ [.v 0; .put_ {@v _;}];",
|
|
977
|
+
"; .log2_ [.count 0; .tick_ {@count (count + 1);}; .set_ {@count _;}];",
|
|
978
|
+
"; cell2_ -> {(ygetters & {_ ()}) .0};",
|
|
979
|
+
"; cell2_ -> {log2_.tick_ ()};",
|
|
980
|
+
"; .poke2 {cell2_.put_ 1; cell2_.v};",
|
|
981
|
+
"; .b1 [.k 1];",
|
|
982
|
+
"; .b2 [.k 2];",
|
|
983
|
+
"; .obj_ [.^ b1; .rebase_ {.^ _;}];",
|
|
984
|
+
"; .objs [{obj_.k}];",
|
|
985
|
+
"; .peek-k {.p 0; .q (b1.k + b2.k); .r (objs & {_ ()}); r .0};",
|
|
986
|
+
"; .peek-k-open {.p 0; obj_.k};",
|
|
987
|
+
"; .rebase {obj_.rebase_ b2; 0};",
|
|
988
|
+
"; .holder_ [.t_ x_; .set-t_ {@t_ _;}];",
|
|
989
|
+
"; .ys [{y_}];",
|
|
990
|
+
"; .retarget-holder {.p 0; .v (ys & {_ ()}); holder_.set-t_ (v .0); 0};",
|
|
991
|
+
"; .via-holder {.a holder_.t_.n; holder_.t_.set_ (a + 1); holder_.t_.n};",
|
|
992
|
+
"; .nested {$$.dispatch.sequential [read-x]};",
|
|
993
|
+
"; state ()",
|
|
994
|
+
"# [5, 10]",
|
|
995
|
+
"```",
|
|
996
|
+
"W1. Shared x, two read-then-write events. The sequential baseline is the",
|
|
997
|
+
"observation every coordinated policy must reproduce.",
|
|
998
|
+
"```",
|
|
999
|
+
"; $$.dispatch.sequential [incr-x, incr-x]",
|
|
1000
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2 1:3”; .waited [[], []]; .escapes [0, 0]; 6, 7]",
|
|
1001
|
+
"; state ()",
|
|
1002
|
+
"# [7, 10]",
|
|
1003
|
+
"; reset ();",
|
|
1004
|
+
"; $$.dispatch.footprint [incr-x, incr-x]",
|
|
1005
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2 1:3”; .waited [[], [0]]; .escapes [0, 0]; 6, 7]",
|
|
1006
|
+
"; state ()",
|
|
1007
|
+
"# [7, 10]",
|
|
1008
|
+
"; reset ();",
|
|
1009
|
+
"; $$.dispatch.interleave [incr-x, incr-x]",
|
|
1010
|
+
"# [.trace “0:1 1:1 0:2 1:2 0:3 1:3”; .waited [[], []]; .escapes [0, 0]; 6, 6]",
|
|
1011
|
+
"; state ()",
|
|
1012
|
+
"# [6, 10]",
|
|
1013
|
+
"; reset ();",
|
|
1014
|
+
"```",
|
|
1015
|
+
"W2. The conflict is on the identity, not the name: a write through a mutable",
|
|
1016
|
+
"alias of x is the same conflict.",
|
|
1017
|
+
"```",
|
|
1018
|
+
"; $$.dispatch.footprint [incr-x, via-alias]",
|
|
1019
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2 1:3”; .waited [[], [0]]; .escapes [0, 0]; 6, 7]",
|
|
1020
|
+
"; state ()",
|
|
1021
|
+
"# [7, 10]",
|
|
1022
|
+
"; reset ();",
|
|
1023
|
+
"```",
|
|
1024
|
+
"W3. Disjoint x and y: the events interleave statement by statement and the",
|
|
1025
|
+
"observation is the baseline's.",
|
|
1026
|
+
"```",
|
|
1027
|
+
"; $$.dispatch.sequential [incr-x, incr-y]",
|
|
1028
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2 1:3”; .waited [[], []]; .escapes [0, 0]; 6, 11]",
|
|
1029
|
+
"; state ()",
|
|
1030
|
+
"# [6, 11]",
|
|
1031
|
+
"; reset ();",
|
|
1032
|
+
"; $$.dispatch.footprint [incr-x, incr-y]",
|
|
1033
|
+
"# [.trace “0:1 1:1 0:2 1:2 0:3 1:3”; .waited [[], []]; .escapes [0, 0]; 6, 11]",
|
|
1034
|
+
"; state ()",
|
|
1035
|
+
"# [6, 11]",
|
|
1036
|
+
"; reset ();",
|
|
1037
|
+
"```",
|
|
1038
|
+
"W4. A reader of x against a writer of x, both orders: the reader is given one",
|
|
1039
|
+
"committed version, the one program order puts before it.",
|
|
1040
|
+
"```",
|
|
1041
|
+
"; $$.dispatch.footprint [incr-x, read-x]",
|
|
1042
|
+
"# [.trace “0:1 0:2 0:3 1:1”; .waited [[], [0]]; .escapes [0, 0]; 6, 6]",
|
|
1043
|
+
"; $$.dispatch.footprint [read-x, incr-x]",
|
|
1044
|
+
"# [.trace “0:1 1:1 1:2 1:3”; .waited [[], [0]]; .escapes [0, 0]; 6, 7]",
|
|
1045
|
+
"; state ()",
|
|
1046
|
+
"# [7, 10]",
|
|
1047
|
+
"; reset ();",
|
|
1048
|
+
"```",
|
|
1049
|
+
"W5. A mutating method through an immutable alias is a functional update: it",
|
|
1050
|
+
"writes nothing shared, so a reader of x need not wait, and x is untouched.",
|
|
1051
|
+
"```",
|
|
1052
|
+
"; $$.dispatch.footprint [functional, read-x]",
|
|
1053
|
+
"# [.trace “0:1 1:1”; .waited [[], []]; .escapes [0, 0]; 0, 5]",
|
|
1054
|
+
"; state ()",
|
|
1055
|
+
"# [5, 10]",
|
|
1056
|
+
"```",
|
|
1057
|
+
"W6. A multi-value invariant, x + y. Uncoordinated statements let a slow reader",
|
|
1058
|
+
"observe a sum that never existed and two transfers lose the conservation;",
|
|
1059
|
+
"footprint keeps both.",
|
|
1060
|
+
"```",
|
|
1061
|
+
"; $$.dispatch.sequential [move, sum-slow]",
|
|
1062
|
+
"# [.trace “0:1 0:2 0:3 0:4 1:1 1:2 1:3”; .waited [[], []]; .escapes [0, 0]; 15, 15]",
|
|
1063
|
+
"; state ()",
|
|
1064
|
+
"# [4, 11]",
|
|
1065
|
+
"; reset ();",
|
|
1066
|
+
"; $$.dispatch.interleave [move, sum-slow]",
|
|
1067
|
+
"# [.trace “0:1 1:1 0:2 1:2 0:3 1:3 0:4”; .waited [[], []]; .escapes [0, 0]; 15, 16]",
|
|
1068
|
+
"; state ()",
|
|
1069
|
+
"# [4, 11]",
|
|
1070
|
+
"; reset ();",
|
|
1071
|
+
"; $$.dispatch.footprint [move, sum-slow]",
|
|
1072
|
+
"# [.trace “0:1 0:2 0:3 0:4 1:1 1:2 1:3”; .waited [[], [0]]; .escapes [0, 0]; 15, 15]",
|
|
1073
|
+
"; state ()",
|
|
1074
|
+
"# [4, 11]",
|
|
1075
|
+
"; reset ();",
|
|
1076
|
+
"; $$.dispatch.interleave [move, move]",
|
|
1077
|
+
"# [.trace “0:1 1:1 0:2 1:2 0:3 1:3 0:4 1:4”; .waited [[], []]; .escapes [0, 0]; 16, 16]",
|
|
1078
|
+
"; state ()",
|
|
1079
|
+
"# [4, 12]",
|
|
1080
|
+
"; reset ();",
|
|
1081
|
+
"; $$.dispatch.footprint [move, move]",
|
|
1082
|
+
"# [.trace “0:1 0:2 0:3 0:4 1:1 1:2 1:3 1:4”; .waited [[], [0]]; .escapes [0, 0]; 15, 15]",
|
|
1083
|
+
"; state ()",
|
|
1084
|
+
"# [3, 12]",
|
|
1085
|
+
"; reset ();",
|
|
1086
|
+
"```",
|
|
1087
|
+
"W7. A dynamically rebound name. `retarget` rebinds `t_` from x to y; `via-t`",
|
|
1088
|
+
"writes through `t_`. Its footprint is read when it starts, after `retarget`,",
|
|
1089
|
+
"so it names y and `incr-y` waits for it.",
|
|
1090
|
+
"```",
|
|
1091
|
+
"; $$.dispatch.sequential [retarget, via-t, incr-y]",
|
|
1092
|
+
"# [.trace “0:1 0:2 1:1 1:2 1:3 2:1 2:2 2:3”; .waited [[], [], []]; .escapes [0, 0, 0]; 10, 11, 12]",
|
|
1093
|
+
"; state ()",
|
|
1094
|
+
"# [5, 12]",
|
|
1095
|
+
"; reset ();",
|
|
1096
|
+
"; $$.dispatch.footprint [retarget, via-t, incr-y]",
|
|
1097
|
+
"# [.trace “0:1 0:2 1:1 1:2 1:3 2:1 2:2 2:3”; .waited [[], [0], [0, 1]]; .escapes [0, 0, 0]; 10, 11, 12]",
|
|
1098
|
+
"; state ()",
|
|
1099
|
+
"# [5, 12]",
|
|
1100
|
+
"; reset ();",
|
|
1101
|
+
"```",
|
|
1102
|
+
"W8. A closure returned by a call and then called. The walk reaches the",
|
|
1103
|
+
"returned closure's body through the name it was written under, so the event",
|
|
1104
|
+
"is seen to write x and is serialized: conservative admission, no refusal.",
|
|
1105
|
+
"```",
|
|
1106
|
+
"; $$.dispatch.footprint [via-mk, incr-x]",
|
|
1107
|
+
"# [.trace “0:1 1:1 1:2 1:3”; .waited [[], [0]]; .escapes [0, 0]; 6, 7]",
|
|
1108
|
+
"; state ()",
|
|
1109
|
+
"# [7, 10]",
|
|
1110
|
+
"; reset ();",
|
|
1111
|
+
"```",
|
|
1112
|
+
"W9. Hostile: a call reached only through data. `hidden-incr-x` reads x and",
|
|
1113
|
+
"writes x through closures held as elements of `getters` and `setters`, which",
|
|
1114
|
+
"the walk reads as aggregates without walking the closures inside. Its",
|
|
1115
|
+
"certificate therefore names neither a read nor a write of x, and the",
|
|
1116
|
+
"dispatcher admits it beside `incr-x`. Uncoordinated, that is a lost update",
|
|
1117
|
+
"with an escape reported after the fact. Under footprint the guard refuses",
|
|
1118
|
+
"the first access outside the certificate, the read of x, before it happens:",
|
|
1119
|
+
"the event ends with `$!.uncertified-read`, nothing it would have written",
|
|
1120
|
+
"lands, and `incr-x` completes alone.",
|
|
1121
|
+
"```",
|
|
1122
|
+
"; $$.dispatch.interleave [hidden-incr-x, incr-x]",
|
|
1123
|
+
"# [.trace “0:1 1:1 0:2 1:2 1:3”; .waited [[], []]; .escapes [1, 0]; 6, 6]",
|
|
1124
|
+
"; state ()",
|
|
1125
|
+
"# [6, 10]",
|
|
1126
|
+
"; reset ();",
|
|
1127
|
+
"; $$.dispatch.footprint [hidden-incr-x, incr-x]",
|
|
1128
|
+
"# [.trace “1:1 1:2 1:3”; .waited [[], []]; .escapes [0, 0]; $!.uncertified-read, 6]",
|
|
1129
|
+
"; state ()",
|
|
1130
|
+
"# [6, 10]",
|
|
1131
|
+
"; reset ();",
|
|
1132
|
+
"```",
|
|
1133
|
+
"W10. Hostile: closures handed in inside a data argument. `each` applies every",
|
|
1134
|
+
"element of its argument; the walk sees the argument as an aggregate and the",
|
|
1135
|
+
"element closures stay unwalked. Refused before the first uncertified access.",
|
|
1136
|
+
"`hidden-write-x` reads x in the open and writes it through the hidden setter:",
|
|
1137
|
+
"its certificate reads x, so a reader of x is admitted beside it, and the",
|
|
1138
|
+
"hidden write is refused at the commit point, before it lands: x keeps the",
|
|
1139
|
+
"value the reader saw.",
|
|
1140
|
+
"```",
|
|
1141
|
+
"; $$.dispatch.footprint [[each, setters], incr-x]",
|
|
1142
|
+
"# [.trace “1:1 1:2 1:3”; .waited [[], []]; .escapes [0, 0]; $!.uncertified-read, 6]",
|
|
1143
|
+
"; state ()",
|
|
1144
|
+
"# [6, 10]",
|
|
1145
|
+
"; reset ();",
|
|
1146
|
+
"; $$.dispatch.footprint [hidden-write-x, read-x]",
|
|
1147
|
+
"# [.trace “0:1 1:1”; .waited [[], []]; .escapes [0, 0]; $!.uncertified-write, 5]",
|
|
1148
|
+
"; state ()",
|
|
1149
|
+
"# [5, 10]",
|
|
1150
|
+
"```",
|
|
1151
|
+
"W11. A hidden effect that is inferable: the arrow `cell_ -> {log_.tick_ ()}`",
|
|
1152
|
+
"registers a callback that writes `log_` whenever `cell_` commits a write. The",
|
|
1153
|
+
"walk reads the registered callbacks of every identity the event may write,",
|
|
1154
|
+
"so `cell-twice` is seen to write `log_` and is serialized against `log-slow`.",
|
|
1155
|
+
"```",
|
|
1156
|
+
"; $$.dispatch.sequential [cell-twice, log-slow]",
|
|
1157
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2 1:3”; .waited [[], []]; .escapes [0, 0]; 2, 12]",
|
|
1158
|
+
"; [cell_.v, log_.count]",
|
|
1159
|
+
"# [2, 12]",
|
|
1160
|
+
"; log_.set-count_ 0;",
|
|
1161
|
+
"; $$.dispatch.footprint [cell-twice, log-slow]",
|
|
1162
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2 1:3”; .waited [[], [0]]; .escapes [0, 0]; 2, 12]",
|
|
1163
|
+
"; [cell_.v, log_.count]",
|
|
1164
|
+
"# [2, 12]",
|
|
1165
|
+
"; log_.set-count_ 0;",
|
|
1166
|
+
"```",
|
|
1167
|
+
"W12. A failing event. `ghost` imports a resource, which the walk cannot read,",
|
|
1168
|
+
"so it is opaque and serialized against everything; it fails at its first",
|
|
1169
|
+
"statement as a call would, writes nothing, and the other event runs after it.",
|
|
1170
|
+
"```",
|
|
1171
|
+
"; $$.dispatch.footprint [ghost, incr-y]",
|
|
1172
|
+
"# [.trace “0:1 1:1 1:2 1:3”; .waited [[], [0]]; .escapes [0, 0]; $!.resource-absent './nothing.hc', 11]",
|
|
1173
|
+
"; state ()",
|
|
1174
|
+
"# [5, 11]",
|
|
1175
|
+
"; reset ();",
|
|
1176
|
+
"```",
|
|
1177
|
+
"W13. A refused event keeps its certified prefix. `prefix-x` writes x, which",
|
|
1178
|
+
"its certificate allows, then reads y through a closure held in data, which",
|
|
1179
|
+
"it does not: it is refused at that read, and x keeps the 6 it committed.",
|
|
1180
|
+
"`read-x` waits for it and reads 6. The baseline that matches is the",
|
|
1181
|
+
"certified serial run, prefix and failure included; the serial run of the",
|
|
1182
|
+
"completed event alone (`read-x`) would read 5, and the plain serial run, in",
|
|
1183
|
+
"which nothing is refused, completes `prefix-x`.",
|
|
1184
|
+
"```",
|
|
1185
|
+
"; $$.dispatch.footprint [prefix-x, read-x]",
|
|
1186
|
+
"# [.trace “0:1 1:1”; .waited [[], [0]]; .escapes [0, 0]; $!.uncertified-read, 6]",
|
|
1187
|
+
"; state ()",
|
|
1188
|
+
"# [6, 10]",
|
|
1189
|
+
"; reset ();",
|
|
1190
|
+
"; $$.dispatch.certified-sequential [prefix-x, read-x]",
|
|
1191
|
+
"# [.trace “0:1 1:1”; .waited [[], []]; .escapes [0, 0]; $!.uncertified-read, 6]",
|
|
1192
|
+
"; state ()",
|
|
1193
|
+
"# [6, 10]",
|
|
1194
|
+
"; reset ();",
|
|
1195
|
+
"; $$.dispatch.sequential [read-x]",
|
|
1196
|
+
"# [.trace “0:1”; .waited [[]]; .escapes [0]; 5]",
|
|
1197
|
+
"; $$.dispatch.sequential [prefix-x, read-x]",
|
|
1198
|
+
"# [.trace “0:1 0:2 0:3 1:1”; .waited [[], []]; .escapes [0, 0]; 10, 6]",
|
|
1199
|
+
"; state ()",
|
|
1200
|
+
"# [6, 10]",
|
|
1201
|
+
"; reset ();",
|
|
1202
|
+
"```",
|
|
1203
|
+
"W14. Arrow registration is a write of the managed value: the subscriber list",
|
|
1204
|
+
"decides what every later write of the value fires. Both orders, each from a",
|
|
1205
|
+
"fresh `w_`. Registered through a closure held in data (`arm-hidden`), the",
|
|
1206
|
+
"registration is outside the certificate and refused before it lands, so no",
|
|
1207
|
+
"callback is added and none fires, in the footprint run and in the certified",
|
|
1208
|
+
"serial run alike; the plain serial run registers and, after it, `poke`",
|
|
1209
|
+
"fires the callback once. Registered by name, even through an immutable",
|
|
1210
|
+
"alias (`arm`), the arrow is in the certificate as a write of w, so the pair",
|
|
1211
|
+
"serializes in program order and fires exactly what the serial run fires.",
|
|
1212
|
+
"```",
|
|
1213
|
+
"; rearm ();",
|
|
1214
|
+
"; $$.dispatch.footprint [arm-hidden, poke]",
|
|
1215
|
+
"# [.trace “0:1 1:1 1:2”; .waited [[], []]; .escapes [0, 0]; $!.uncertified-write, 0]",
|
|
1216
|
+
"; watch ()",
|
|
1217
|
+
"# [1, 0]",
|
|
1218
|
+
"; rearm ();",
|
|
1219
|
+
"; $$.dispatch.certified-sequential [arm-hidden, poke]",
|
|
1220
|
+
"# [.trace “0:1 1:1 1:2”; .waited [[], []]; .escapes [0, 0]; $!.uncertified-write, 0]",
|
|
1221
|
+
"; watch ()",
|
|
1222
|
+
"# [1, 0]",
|
|
1223
|
+
"; rearm ();",
|
|
1224
|
+
"; $$.dispatch.sequential [arm-hidden, poke]",
|
|
1225
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2”; .waited [[], []]; .escapes [1, 0]; 0, 1]",
|
|
1226
|
+
"; watch ()",
|
|
1227
|
+
"# [1, 1]",
|
|
1228
|
+
"; rearm ();",
|
|
1229
|
+
"; $$.dispatch.footprint [poke-late, arm-hidden]",
|
|
1230
|
+
"# [.trace “0:1 1:1 0:2 0:3”; .waited [[], []]; .escapes [0, 0]; 0, $!.uncertified-write]",
|
|
1231
|
+
"; watch ()",
|
|
1232
|
+
"# [1, 0]",
|
|
1233
|
+
"; rearm ();",
|
|
1234
|
+
"; $$.dispatch.certified-sequential [poke-late, arm-hidden]",
|
|
1235
|
+
"# [.trace “0:1 0:2 0:3 1:1”; .waited [[], []]; .escapes [0, 0]; 0, $!.uncertified-write]",
|
|
1236
|
+
"; watch ()",
|
|
1237
|
+
"# [1, 0]",
|
|
1238
|
+
"; rearm ();",
|
|
1239
|
+
"; $$.dispatch.footprint [arm, poke]",
|
|
1240
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2”; .waited [[], [0]]; .escapes [0, 0]; 0, 1]",
|
|
1241
|
+
"; watch ()",
|
|
1242
|
+
"# [1, 1]",
|
|
1243
|
+
"; rearm ();",
|
|
1244
|
+
"; $$.dispatch.sequential [arm, poke]",
|
|
1245
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2”; .waited [[], []]; .escapes [0, 0]; 0, 1]",
|
|
1246
|
+
"; watch ()",
|
|
1247
|
+
"# [1, 1]",
|
|
1248
|
+
"; rearm ();",
|
|
1249
|
+
"; $$.dispatch.footprint [poke-late, arm]",
|
|
1250
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2 1:3”; .waited [[], [0]]; .escapes [0, 0]; 0, 0]",
|
|
1251
|
+
"; watch ()",
|
|
1252
|
+
"# [1, 0]",
|
|
1253
|
+
"; rearm ();",
|
|
1254
|
+
"; $$.dispatch.sequential [poke-late, arm]",
|
|
1255
|
+
"# [.trace “0:1 0:2 0:3 1:1 1:2 1:3”; .waited [[], []]; .escapes [0, 0]; 0, 0]",
|
|
1256
|
+
"; watch ()",
|
|
1257
|
+
"# [1, 0]",
|
|
1258
|
+
"; rearm ();",
|
|
1259
|
+
"```",
|
|
1260
|
+
"W15. A refusal inside an arrow callback ends the event there. `cell2_` has",
|
|
1261
|
+
"two callbacks: the first reads y through data, outside the certificate; the",
|
|
1262
|
+
"second ticks `log2_`. Writing `cell2_` commits (the certified prefix), the",
|
|
1263
|
+
"first callback is refused, and the second does not run: `log2_` stays 0. The",
|
|
1264
|
+
"plain serial run, with no guard, runs both.",
|
|
1265
|
+
"```",
|
|
1266
|
+
"; $$.dispatch.footprint [poke2]",
|
|
1267
|
+
"# [.trace “”; .waited [[]]; .escapes [0]; $!.uncertified-read]",
|
|
1268
|
+
"; [cell2_.v, log2_.count]",
|
|
1269
|
+
"# [1, 0]",
|
|
1270
|
+
"; cell2_.put_ 0;",
|
|
1271
|
+
"; log2_.set_ 0;",
|
|
1272
|
+
"; $$.dispatch.certified-sequential [poke2]",
|
|
1273
|
+
"# [.trace “”; .waited [[]]; .escapes [0]; $!.uncertified-read]",
|
|
1274
|
+
"; [cell2_.v, log2_.count]",
|
|
1275
|
+
"# [1, 0]",
|
|
1276
|
+
"; cell2_.put_ 0;",
|
|
1277
|
+
"; log2_.set_ 0;",
|
|
1278
|
+
"; $$.dispatch.sequential [poke2]",
|
|
1279
|
+
"# [.trace “0:1 0:2”; .waited [[]]; .escapes [0]; 1]",
|
|
1280
|
+
"; [cell2_.v, log2_.count]",
|
|
1281
|
+
"# [1, 1]",
|
|
1282
|
+
"; cell2_.put_ 0;",
|
|
1283
|
+
"; log2_.set_ 0;",
|
|
1284
|
+
"```",
|
|
1285
|
+
"W16. A lookup that misses is a read. `obj_` declares no `k`; `obj_.k` falls",
|
|
1286
|
+
"through to its parent. `peek-k` reads b1 and b2 by name and `obj_.k`",
|
|
1287
|
+
"through data, so its certificate reads neither `obj_` nor its parent edge,",
|
|
1288
|
+
"and `rebase` (which re-parents `obj_` to b2) is admitted beside it. The",
|
|
1289
|
+
"miss on `obj_` is refused before the lookup falls through, whichever parent",
|
|
1290
|
+
"is current, so the answer does not depend on the schedule. Looked up by",
|
|
1291
|
+
"name (`peek-k-open`), the miss is in the certificate and the pair",
|
|
1292
|
+
"serializes.",
|
|
1293
|
+
"```",
|
|
1294
|
+
"; $$.dispatch.footprint [peek-k, rebase]",
|
|
1295
|
+
"# [.trace “0:1 1:1 0:2 1:2”; .waited [[], []]; .escapes [0, 0]; $!.uncertified-read, 0]",
|
|
1296
|
+
"; obj_.k",
|
|
1297
|
+
"# 2",
|
|
1298
|
+
"; obj_.rebase_ b1;",
|
|
1299
|
+
"; $$.dispatch.certified-sequential [peek-k, rebase]",
|
|
1300
|
+
"# [.trace “0:1 0:2 1:1 1:2”; .waited [[], []]; .escapes [0, 0]; $!.uncertified-read, 0]",
|
|
1301
|
+
"; obj_.k",
|
|
1302
|
+
"# 2",
|
|
1303
|
+
"; obj_.rebase_ b1;",
|
|
1304
|
+
"; $$.dispatch.footprint [peek-k-open, rebase]",
|
|
1305
|
+
"# [.trace “0:1 0:2 1:1 1:2”; .waited [[], [0]]; .escapes [0, 0]; 1, 0]",
|
|
1306
|
+
"; obj_.k",
|
|
1307
|
+
"# 2",
|
|
1308
|
+
"; obj_.rebase_ b1;",
|
|
1309
|
+
"; $$.dispatch.sequential [peek-k-open, rebase]",
|
|
1310
|
+
"# [.trace “0:1 0:2 1:1 1:2”; .waited [[], []]; .escapes [0, 0]; 1, 0]",
|
|
1311
|
+
"; obj_.k",
|
|
1312
|
+
"# 2",
|
|
1313
|
+
"; obj_.rebase_ b1;",
|
|
1314
|
+
"```",
|
|
1315
|
+
"W17. Admission is in program order. `retarget-holder` points `holder_.t_` at",
|
|
1316
|
+
"y through data its certificate does not follow; `via-holder` waits for it",
|
|
1317
|
+
"and, when it starts, is seen to write y. `incr-y` must not start before",
|
|
1318
|
+
"`via-holder` has: had it run ahead, `via-holder` would increment the y it",
|
|
1319
|
+
"had already written, and the two results would swap.",
|
|
1320
|
+
"```",
|
|
1321
|
+
"; $$.dispatch.sequential [retarget-holder, via-holder, incr-y]",
|
|
1322
|
+
"# [.trace “0:1 0:2 0:3 0:4 1:1 1:2 1:3 2:1 2:2 2:3”; .waited [[], [], []]; .escapes [0, 0, 0]; 0, 11, 12]",
|
|
1323
|
+
"; state ()",
|
|
1324
|
+
"# [5, 12]",
|
|
1325
|
+
"; holder_.set-t_ x_;",
|
|
1326
|
+
"; reset ();",
|
|
1327
|
+
"; $$.dispatch.footprint [retarget-holder, via-holder, incr-y]",
|
|
1328
|
+
"# [.trace “0:1 0:2 0:3 0:4 1:1 1:2 1:3 2:1 2:2 2:3”; .waited [[], [0], [1]]; .escapes [0, 0, 0]; 0, 11, 12]",
|
|
1329
|
+
"; state ()",
|
|
1330
|
+
"# [5, 12]",
|
|
1331
|
+
"; holder_.set-t_ x_;",
|
|
1332
|
+
"; reset ();",
|
|
1333
|
+
"```",
|
|
1334
|
+
"W18. A dispatch inside an event. The host namespace `$$` is state the walk",
|
|
1335
|
+
"does not follow, so under a guard an event that reaches for `$$.dispatch` is",
|
|
1336
|
+
"refused at that read, before any inner event runs; unguarded, it nests. A",
|
|
1337
|
+
"nested dispatch reached from the host is covered by the companion test: a",
|
|
1338
|
+
"refusal belongs to the guard that refused it.",
|
|
1339
|
+
"```",
|
|
1340
|
+
"; $$.dispatch.footprint [nested]",
|
|
1341
|
+
"# [.trace “”; .waited [[]]; .escapes [0]; $!.uncertified-read]",
|
|
1342
|
+
"; $$.dispatch.sequential [nested]",
|
|
1343
|
+
"# [.trace “0:1”; .waited [[]]; .escapes [0]; [.trace “0:1”; .waited [[]]; .escapes [0]; 5]]",
|
|
1344
|
+
"```",
|
|
1345
|
+
"Refusals of the bridge itself: an element that is not a callable, and a bare",
|
|
1346
|
+
"policy, which is a value.",
|
|
1347
|
+
"```",
|
|
1348
|
+
"; $$.dispatch.footprint [5]",
|
|
1349
|
+
"# $!.dispatch-event 0 FrameCount",
|
|
1350
|
+
"; $$.dispatch.footprint",
|
|
1351
|
+
"# $$.dispatch.footprint",
|
|
1352
|
+
"```",
|
|
1353
|
+
"Importing skips the examples and ends on a native true value.",
|
|
1354
|
+
"```",
|
|
1355
|
+
"[] = []",
|
|
1356
|
+
"",
|
|
1357
|
+
].join("\n"),
|
|
1358
|
+
],
|
|
890
1359
|
[
|
|
891
1360
|
"hc/class-support.hc",
|
|
892
1361
|
[
|
|
@@ -1483,7 +1952,9 @@ export const HC_SOURCES = new Map([
|
|
|
1483
1952
|
"Import it to construct Demis directly: `Demis <- './hc/demi.hc'`, then",
|
|
1484
1953
|
"`Demis.Demi [0, 0, 0]`.",
|
|
1485
1954
|
"",
|
|
1486
|
-
"**State (007.25c).** `Demi [C, L, R]` takes three Counts, any of them zero
|
|
1955
|
+
"**State (007.25c).** `Demi [C, L, R]` takes three Counts, any of them zero",
|
|
1956
|
+
'(`Demi [C, loads]` takes a Count and a list of loads; see "Channels and',
|
|
1957
|
+
'division" below). `C`',
|
|
1487
1958
|
"is the full application Count the state has recorded, not its parity, so",
|
|
1488
1959
|
"`Demi [2, 5, 1]` and `Demi [4, 5, 1]` are different states that agree in phase",
|
|
1489
1960
|
"and in both loads. Anything else is refused with `$!!.invalid-demi`, a named",
|
|
@@ -1595,42 +2066,114 @@ export const HC_SOURCES = new Map([
|
|
|
1595
2066
|
"**Text.** A Demi prints as what it is, an aggregate of fields and methods. As",
|
|
1596
2067
|
"text it reads `Demi(C,L,R)`, with the Count and both loads.",
|
|
1597
2068
|
"",
|
|
2069
|
+
"**Channels and division (007.27).** The two loads are the arity-two case of an",
|
|
2070
|
+
"ordered list of channel loads. `Demi [C, loads]` takes a Count and a nonempty",
|
|
2071
|
+
"list of Counts: two loads are this binary Demi, the same instance",
|
|
2072
|
+
"`Demi [C, L, R]` builds, and any other number is a channel Demi. Every Demi",
|
|
2073
|
+
"stores `count` and `loads`; only the binary one also has `left`, `right` and",
|
|
2074
|
+
"`phase`, which it writes together with `loads`. A channel Demi of arity k",
|
|
2075
|
+
"deposits into channel `C mod k`, which for k = 2 is the phase's channel. Its",
|
|
2076
|
+
"Size is the sum of its loads and its residual their alternating sum",
|
|
2077
|
+
"`e0 − e1 + e2 − …`, the list residual, which for two loads is `L − R`. Its",
|
|
2078
|
+
"fourth hash is intrinsic too: a fresh equal Demi of the same arity. Its `*`,",
|
|
2079
|
+
"`scale_` and ratios are as here. Its `+` and `-` follow the residual's signs:",
|
|
2080
|
+
"`-` deposits on the first even load, load 0, raising the residual, and `+` on",
|
|
2081
|
+
"the first odd load, load 1, lowering it, which for two loads are left and",
|
|
2082
|
+
"right; with one load `+` is `$!!.invalid-arity`. Text reads `Demi(C,[e0, e1,",
|
|
2083
|
+
"…])`.",
|
|
2084
|
+
"",
|
|
2085
|
+
"`d ./ n`, also spelled `d / n`, redistributes the Size: it keeps C and the",
|
|
2086
|
+
"total S and deals S Size units round-robin into n channels, so the first",
|
|
2087
|
+
"S mod n hold ⌈S/n⌉ and the rest ⌊S/n⌋. It is idempotent, `(d ./ n) ./ m` is",
|
|
2088
|
+
"`d ./ m`, and equal Count and Size give equal results, so `Demi(3,[5,2])` and",
|
|
2089
|
+
"`Demi(3,[4,3])` divide into the same `Demi(3,[3,2,2])`. It is not scalar",
|
|
2090
|
+
"division and not the ratios: no number is answered. The divisor is a positive",
|
|
2091
|
+
"Count, refused as a list refuses it (`$!.division-by-zero /`,",
|
|
2092
|
+
"`$!.division-domain /`), never read as a Size. `hc/division.hc` is its",
|
|
2093
|
+
"specification, with the list and RotorRouter divisions beside it.",
|
|
2094
|
+
"",
|
|
1598
2095
|
"**Methods read their own state through `_^`.** A bare name inside a method is",
|
|
1599
2096
|
"looked up on the argument first (spec 7), and a Demi is applied to arbitrary",
|
|
1600
2097
|
"Frames, so a bare `left` could read the argument's field. `_^` is the receiver",
|
|
1601
2098
|
"from a method's body, and `_^^` from a block one level in, because carets",
|
|
1602
2099
|
"count lexically (spec a06). What a branch needs is bound as a local at method",
|
|
1603
|
-
"level, where nested blocks read it.",
|
|
1604
|
-
"
|
|
1605
|
-
"
|
|
1606
|
-
"
|
|
2100
|
+
"level, where nested blocks read it. The file's own names, the constructor",
|
|
2101
|
+
"`Demi` and the helpers `deposit-at` (a cursor that adds a Size at one channel",
|
|
2102
|
+
"index, applied by reduce) and `redistribution` (the round-robin loads of S",
|
|
2103
|
+
"units in n channels), are read the same way, through the scope a caret ladder",
|
|
2104
|
+
"reaches, `(_^^^ .Demi)` from a branch, so an argument's fields never stand in",
|
|
2105
|
+
"for them.",
|
|
2106
|
+
"```",
|
|
2107
|
+
".deposit-at {.at (_ .0); .by (_ .1); [.index 0; .target at; .amount by; .out [];",
|
|
2108
|
+
" .apply_ {.v _; .i (_^ .index); .t (_^ .target); .a (_^ .amount); .o (_^ .out);",
|
|
2109
|
+
" @out (o ((i = t) ? {v + a} : {v})); @index (i + 1);}]};",
|
|
2110
|
+
".redistribution {.s (_ .0); .ways (_ .1); .r (s %% ways); .q (((s - r) / ways).##);",
|
|
2111
|
+
" ((ways - r) [q]) | (r [(q + 1)])};",
|
|
2112
|
+
".binary-demi {.c (_ .0); .l (_ .1); .r (_ .2); .p (((c %% 2) = 0) ? {2} : {1}); [",
|
|
1607
2113
|
" .count c;",
|
|
1608
2114
|
" .phase p;",
|
|
1609
2115
|
" .left l;",
|
|
1610
2116
|
" .right r;",
|
|
2117
|
+
" .loads [l, r];",
|
|
1611
2118
|
" .# {_^.count};",
|
|
1612
2119
|
" .## {_^.left + _^.right};",
|
|
1613
2120
|
" .### {_^.left - _^.right};",
|
|
1614
2121
|
" .apply_ {.s (_ .##); .c (_^ .count); .l (_^ .left); .r (_^ .right); .p (_^ .phase);",
|
|
1615
|
-
" (s ~ (0.<>)) ? {(p = 2) ? {@left (l + s); @phase 1;} : {@right (r + s); @phase 2;}; @count (c + 1); _^^} : {s}};",
|
|
2122
|
+
" (s ~ (0.<>)) ? {(p = 2) ? {@left (l + s); @loads [(l + s), r]; @phase 1;} : {@right (r + s); @loads [l, (r + s)]; @phase 2;}; @count (c + 1); _^^} : {s}};",
|
|
1616
2123
|
" .scale_ {.k _; .l (_^ .left); .r (_^ .right);",
|
|
1617
|
-
" (k ~ (0.<>)) ? {@left (l * k); @right (r * k); _^^} : {$!!.invalid-scale}};",
|
|
1618
|
-
" .deposit-right_ {.k _; .r (_^ .right);",
|
|
1619
|
-
" (k ~ (0.<>)) ? {@right (r + k); _^^} : {$!!.invalid-demi}};",
|
|
1620
|
-
" .deposit-left_ {.k _; .l (_^ .left);",
|
|
1621
|
-
" (k ~ (0.<>)) ? {@left (l + k); _^^} : {$!!.invalid-demi}};",
|
|
2124
|
+
" (k ~ (0.<>)) ? {@left (l * k); @right (r * k); @loads [(l * k), (r * k)]; _^^} : {$!!.invalid-scale}};",
|
|
2125
|
+
" .deposit-right_ {.k _; .l (_^ .left); .r (_^ .right);",
|
|
2126
|
+
" (k ~ (0.<>)) ? {@right (r + k); @loads [l, (r + k)]; _^^} : {$!!.invalid-demi}};",
|
|
2127
|
+
" .deposit-left_ {.k _; .l (_^ .left); .r (_^ .right);",
|
|
2128
|
+
" (k ~ (0.<>)) ? {@left (l + k); @loads [(l + k), r]; _^^} : {$!!.invalid-demi}};",
|
|
1622
2129
|
" .+ {.s (_ .##);",
|
|
1623
2130
|
" (s ~ (0.<>)) ? {(_^^ .deposit-right_ s)} : {s}};",
|
|
1624
2131
|
" .- {.s (_ .##);",
|
|
1625
2132
|
" (s ~ (0.<>)) ? {(_^^ .deposit-left_ s)} : {s}};",
|
|
1626
2133
|
" .* {.s (_ .##);",
|
|
1627
2134
|
" (s ~ (0.<>)) ? {(_^^ .scale_ s)} : {s}};",
|
|
2135
|
+
" ./ {.ways _; .c (_^ .count); .s (_^ .##); .v ([] / ways);",
|
|
2136
|
+
" (v ~ ([].<>)) ? {(_^^^ .Demi) [c, ((_^^^ .redistribution) [s, ways])]} : {v}};",
|
|
1628
2137
|
" .size-ratio {.c (_^ .count); .s (_^ .##); .u ((_ = ()) ? {1} : {0});",
|
|
1629
2138
|
" (c .> 0) ? {(u = 1) ? {s / c} : {$!!.unary-observation}}};",
|
|
1630
2139
|
" .residual-ratio {.c (_^ .count); .d (_^ .###); .u ((_ = ()) ? {1} : {0});",
|
|
1631
2140
|
" (c .> 0) ? {(u = 1) ? {d / c} : {$!!.unary-observation}}};",
|
|
1632
2141
|
" .toText {“Demi(” (_^ .count) “,” (_^ .left) “,” (_^ .right) “)”}",
|
|
1633
|
-
" ]}
|
|
2142
|
+
" ]};",
|
|
2143
|
+
".channel-demi {.c (_ .0); .e (_ .1); [",
|
|
2144
|
+
" .count c;",
|
|
2145
|
+
" .loads e;",
|
|
2146
|
+
" .# {_^.count};",
|
|
2147
|
+
" .## {(_^ .loads).##};",
|
|
2148
|
+
" .### {(_^ .loads).###};",
|
|
2149
|
+
" .apply_ {.s (_ .##); .c (_^ .count); .e (_^ .loads);",
|
|
2150
|
+
" (s ~ (0.<>)) ? {@loads ((e | ((_^^^ .deposit-at) [(c %% (e.#)), s])) .out); @count (c + 1); _^^} : {s}};",
|
|
2151
|
+
" .scale_ {.k _; .e (_^ .loads);",
|
|
2152
|
+
" (k ~ (0.<>)) ? {@loads (e & {_ * k}); _^^} : {$!!.invalid-scale}};",
|
|
2153
|
+
" .deposit-right_ {.k _; .e (_^ .loads);",
|
|
2154
|
+
" ((k ~ (0.<>)) ? {(e.#) .> 1}) ? {@loads ((e | ((_^^^ .deposit-at) [1, k])) .out); _^^} : {(k ~ (0.<>)) ? {$!!.invalid-arity} : {$!!.invalid-demi}}};",
|
|
2155
|
+
" .deposit-left_ {.k _; .e (_^ .loads);",
|
|
2156
|
+
" (k ~ (0.<>)) ? {@loads ((e | ((_^^^ .deposit-at) [0, k])) .out); _^^} : {$!!.invalid-demi}};",
|
|
2157
|
+
" .+ {.s (_ .##);",
|
|
2158
|
+
" (s ~ (0.<>)) ? {(_^^ .deposit-right_ s)} : {s}};",
|
|
2159
|
+
" .- {.s (_ .##);",
|
|
2160
|
+
" (s ~ (0.<>)) ? {(_^^ .deposit-left_ s)} : {s}};",
|
|
2161
|
+
" .* {.s (_ .##);",
|
|
2162
|
+
" (s ~ (0.<>)) ? {(_^^ .scale_ s)} : {s}};",
|
|
2163
|
+
" ./ {.ways _; .c (_^ .count); .s (_^ .##); .v ([] / ways);",
|
|
2164
|
+
" (v ~ ([].<>)) ? {(_^^^ .Demi) [c, ((_^^^ .redistribution) [s, ways])]} : {v}};",
|
|
2165
|
+
" .size-ratio {.c (_^ .count); .s (_^ .##); .u ((_ = ()) ? {1} : {0});",
|
|
2166
|
+
" (c .> 0) ? {(u = 1) ? {s / c} : {$!!.unary-observation}}};",
|
|
2167
|
+
" .residual-ratio {.c (_^ .count); .d (_^ .###); .u ((_ = ()) ? {1} : {0});",
|
|
2168
|
+
" (c .> 0) ? {(u = 1) ? {d / c} : {$!!.unary-observation}}};",
|
|
2169
|
+
" .toText {“Demi(” (_^ .count) “,” (_^ .loads) “)”}",
|
|
2170
|
+
" ]};",
|
|
2171
|
+
".Demi {((_ ~ ([].<>)) ? {(__ .#) ~ <2, 3>}) ? {.a __; .c (a .0);",
|
|
2172
|
+
" .boxed (((a.#) = 3) ? {[[a .1, a .2]]} : {[a .1]});",
|
|
2173
|
+
" ((c ~ (0.<>)) ? {(boxed .0) ~ ([].<>)}) ? {.e (boxed .0); .k (e.#);",
|
|
2174
|
+
" ((k .> 0) ? {(e &| {.x _; (x ~ (0.<>)) ? {[]} : {[x]}}).# = 0}) ? {",
|
|
2175
|
+
" (k = 2) ? {binary-demi [c, (e .0), (e .1)]} : {channel-demi [c, (e | [])]}",
|
|
2176
|
+
" } : {$!!.invalid-demi}} : {$!!.invalid-demi}} : {$!!.invalid-demi}};",
|
|
1634
2177
|
"```",
|
|
1635
2178
|
"## Construction",
|
|
1636
2179
|
"",
|
|
@@ -2107,12 +2650,15 @@ export const HC_SOURCES = new Map([
|
|
|
2107
2650
|
"",
|
|
2108
2651
|
"A reading takes no divisor. It is applied to nil, and an operand is refused",
|
|
2109
2652
|
"rather than read as the divisor, so it is neither `/` nor `%%`. The class",
|
|
2110
|
-
"declares
|
|
2653
|
+
"declares no `%%`, which answers nil as for any aggregate without one. Its `/`,",
|
|
2654
|
+
"also spelled `./`, is not a ratio either: it redistributes the Size into that",
|
|
2655
|
+
"many channels and keeps the Count (007.27, below), so `A / 4` is a Demi of four",
|
|
2656
|
+
"loads and no number",
|
|
2111
2657
|
"```",
|
|
2112
2658
|
"; [A.size-ratio 4, A.residual-ratio [], A.size-ratio 0, A.residual-ratio “abc”]",
|
|
2113
2659
|
"# [$!!.unary-observation, $!!.unary-observation, $!!.unary-observation, $!!.unary-observation]",
|
|
2114
|
-
"; [A / 4, A %% 4]",
|
|
2115
|
-
"# [(
|
|
2660
|
+
"; [“” (A / 4), A %% 4]",
|
|
2661
|
+
"# [“Demi(2,[2, 2, 1, 1])”, ()]",
|
|
2116
2662
|
"```",
|
|
2117
2663
|
"A reading at the wrong depth fails safe. Inside a branch `_^` is not the",
|
|
2118
2664
|
"receiver, so a reading written that way answers `$!.name-missing` and no ratio",
|
|
@@ -2189,6 +2735,459 @@ export const HC_SOURCES = new Map([
|
|
|
2189
2735
|
"",
|
|
2190
2736
|
].join("\n"),
|
|
2191
2737
|
],
|
|
2738
|
+
[
|
|
2739
|
+
"hc/division.hc",
|
|
2740
|
+
[
|
|
2741
|
+
"#!/usr/bin/env hc",
|
|
2742
|
+
"```",
|
|
2743
|
+
"Literal division (occurrence/figure 007.26, 007.27, 007.27c)",
|
|
2744
|
+
"",
|
|
2745
|
+
"Division by n, taken literally, is dealing a pile into n channels in turn: the",
|
|
2746
|
+
"first to channel 0, the next to channel 1, and so on round the n channels.",
|
|
2747
|
+
"Parity is the case n = 2. Nothing about it needs a host divisor, a quotient",
|
|
2748
|
+
"type or a fraction; it redistributes what is there and keeps its total.",
|
|
2749
|
+
"",
|
|
2750
|
+
"`x ./ n` is that dealing for three receivers. `./` is the dotted spelling of `/`",
|
|
2751
|
+
'(GRAMMAR "Mathematical Operators"), so `x / n` means the same, and a pair of',
|
|
2752
|
+
"numbers keeps its exact numeric division: `6 ./ 3` is 2 and `7 ./ 2` is 7/2.",
|
|
2753
|
+
"The divisor is always the channel Count itself: a positive Count, never a Size",
|
|
2754
|
+
"read from some other Frame.",
|
|
2755
|
+
"",
|
|
2756
|
+
"- **A list** (an array or a group) deals its immediate elements whole, in",
|
|
2757
|
+
" order, into n channels: the element at index i goes to channel i mod n.",
|
|
2758
|
+
" Elements are the same Frames, never copied, evaluated, measured or",
|
|
2759
|
+
" flattened, so identity, nesting and duplicates are kept. Properties are not",
|
|
2760
|
+
" elements and are not dealt. The answer is a `RotorRouter` of those n",
|
|
2761
|
+
" channels, read as `.channels`, not a bare list of lists (007.27c): a list",
|
|
2762
|
+
" whose children happen to be lists is a plain list, and a router keeps its",
|
|
2763
|
+
" channels as channels, so dividing the answer again re-deals the same Frames.",
|
|
2764
|
+
" The dealing is native, in `/`.",
|
|
2765
|
+
"- **A RotorRouter** (`hc/rotor-router.hc`) keeps the Frames it routed, so it",
|
|
2766
|
+
" re-deals them: it reconstructs the order they were routed in from its",
|
|
2767
|
+
" channels, which a round-robin history fixes, and routes that history through",
|
|
2768
|
+
" a fresh router of n channels. Its Count is unchanged and its next route goes",
|
|
2769
|
+
" to channel C mod n.",
|
|
2770
|
+
"- **A Demi** (`hc/demi.hc`) forgot its Frames and kept only their Sizes, so it",
|
|
2771
|
+
" deals Size units. `D ./ n` keeps the Count C and the total Size S and",
|
|
2772
|
+
" canonicalizes the loads to S units dealt round-robin into n channels, so the",
|
|
2773
|
+
" first S mod n channels hold ⌈S/n⌉ and the rest ⌊S/n⌋. Its next application",
|
|
2774
|
+
" deposits into channel C mod n.",
|
|
2775
|
+
"",
|
|
2776
|
+
"Router and list deal whole Frames, and a Demi deals Size units. Both conserve",
|
|
2777
|
+
"the summed Size, but their channel loads differ in general: children of Sizes",
|
|
2778
|
+
"5 and 2 dealt whole into two channels load them 5 and 2, while a Demi of Size 7",
|
|
2779
|
+
"normalizes to 4 and 3. No law makes them commute, and none is claimed here.",
|
|
2780
|
+
"",
|
|
2781
|
+
"Refusals are the native ones for all three: a divisor of zero is",
|
|
2782
|
+
"`$!.division-by-zero /`, as it is for numbers, and anything but a Count is",
|
|
2783
|
+
"`$!.division-domain /`, a negative or fractional number, a decimal, text, an",
|
|
2784
|
+
"aggregate or a Demi included. A divisor above both 1,000,000 and the element count is `$!.repetition-size 1000000`, checked before anything is built; up to the element count is always allowed, so the answer stays proportional to the list.",
|
|
2785
|
+
"```",
|
|
2786
|
+
"```",
|
|
2787
|
+
"## Lists",
|
|
2788
|
+
"",
|
|
2789
|
+
"Seven Frames dealt into three channels: the element at index i goes to channel",
|
|
2790
|
+
"i mod 3. Nested arrays, an aggregate with a property, a closure and a group are",
|
|
2791
|
+
"each one element, dealt whole. The answer is the router of those channels",
|
|
2792
|
+
"```",
|
|
2793
|
+
"; .A [1, [2]]; .B “b”; .C {5 + 3}; .D [.k 9; 4]; .E 5; .F (6, 7); .G 7;",
|
|
2794
|
+
"; .xs [A, B, C, D, E, F, G];",
|
|
2795
|
+
"; “” (xs ./ 3)",
|
|
2796
|
+
"# “RotorRouter([[[1, [2]], [.k 9; 4], 7], [“b”, 5], [{ 5 + 3 }, (6, 7)]])”",
|
|
2797
|
+
"; .t ((xs ./ 3).channels);",
|
|
2798
|
+
"; [t, t & {_.#}, (xs / 3) = (xs ./ 3), ((t .0) .1).k, (xs ./ 3).#]",
|
|
2799
|
+
"# [[[[1, [2]], [.k 9; 4], 7], [“b”, 5], [{ 5 + 3 }, (6, 7)]], [3, 2, 2], <>, 9, 7]",
|
|
2800
|
+
"```",
|
|
2801
|
+
"Each channel holds the same Frames, in their original order, each once. A",
|
|
2802
|
+
"Frame that occurs twice is dealt twice, and both are it",
|
|
2803
|
+
"```",
|
|
2804
|
+
"; [(t .0) &| {[_ === A]}, (t .2) &| {[_ === C]}, (t &| {_}).#, (t &| {_}) = [A, D, G, B, E, C, F]]",
|
|
2805
|
+
"# [[<>, (), ()], [<>, ()], 7, <>]",
|
|
2806
|
+
"; [([A, A, A] ./ 2).channels, ([A, A, A] ./ 2).channels &| {_} &| {[_ === A]}]",
|
|
2807
|
+
"# [[[[1, [2]], [1, [2]]], [[1, [2]]]], [<>, <>, <>]]",
|
|
2808
|
+
"```",
|
|
2809
|
+
"Two channels are the binary router, with its `left`, `right` and `phase`. One",
|
|
2810
|
+
"channel is the whole list, and more channels than elements leave the last ones",
|
|
2811
|
+
"empty. An empty list deals into n empty channels; empty elements are dealt",
|
|
2812
|
+
"like any other",
|
|
2813
|
+
"```",
|
|
2814
|
+
"; [“” ([1, 2, 3] ./ 2), ([1, 2, 3] ./ 2).left, ([1, 2, 3] ./ 2).phase]",
|
|
2815
|
+
"# [“RotorRouter([1, 3],[2])”, [1, 3], 1]",
|
|
2816
|
+
"; [(xs ./ 1).channels, ([1, 2] ./ 5).channels, ([] ./ 3).channels, ([[], []] ./ 2).channels]",
|
|
2817
|
+
"# [[[[1, [2]], “b”, { 5 + 3 }, [.k 9; 4], 5, (6, 7), 7]], [[1], [2], [], [], []], [[], [], []], [[[]], [[]]]]",
|
|
2818
|
+
"```",
|
|
2819
|
+
"Properties are not elements, so they are not dealt. A group deals its elements",
|
|
2820
|
+
"too, and its channels are arrays",
|
|
2821
|
+
"```",
|
|
2822
|
+
"; [([.k 1; 1, 2, 3] ./ 2).channels, ((1, 2, 3) ./ 2).channels]",
|
|
2823
|
+
"# [[[1, 3], [2]], [[1, 3], [2]]]",
|
|
2824
|
+
"```",
|
|
2825
|
+
"The channel Counts are the canonical dealing: for seven elements into three",
|
|
2826
|
+
"channels they are 3, 2, 2, whatever the elements are",
|
|
2827
|
+
"```",
|
|
2828
|
+
"; [(xs ./ 3).channels & {_.#}, ((7 [0]) ./ 3).channels & {_.#}, ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ./ 4).channels & {_.#}]",
|
|
2829
|
+
"# [[3, 2, 2], [3, 2, 2], [3, 3, 2, 2]]",
|
|
2830
|
+
"```",
|
|
2831
|
+
"## Dividing a division (007.27c)",
|
|
2832
|
+
"",
|
|
2833
|
+
"A division keeps its channels as channels, so dividing it again reads them",
|
|
2834
|
+
"breadth-first, the first of each channel, then the second of each, and deals",
|
|
2835
|
+
"that sequence: `(X ./ n) ./ m` is `X ./ m`, the same Frames in the same",
|
|
2836
|
+
"order, with no extra nesting. Dividing by the same n again changes nothing",
|
|
2837
|
+
"```",
|
|
2838
|
+
"; .X [A, 2, 3, 4, 5, 6];",
|
|
2839
|
+
"; [“” (X ./ 2), “” ((X ./ 2) ./ 2), ((X ./ 2) ./ 2) = (X ./ 2), ((X ./ 2) ./ 3) = (X ./ 3), ((X ./ 3) ./ 2) = (X ./ 2)]",
|
|
2840
|
+
"# [“RotorRouter([[1, [2]], 3, 5],[2, 4, 6])”, “RotorRouter([[1, [2]], 3, 5],[2, 4, 6])”, <>, <>, <>]",
|
|
2841
|
+
"; [((X ./ 2) ./ 3).channels, (((X ./ 2) ./ 3).channels .0 .0) === A]",
|
|
2842
|
+
"# [[[[1, [2]], 4], [2, 5], [3, 6]], <>]",
|
|
2843
|
+
"```",
|
|
2844
|
+
"A plain list whose children are lists is not a division: its two children are",
|
|
2845
|
+
"two whole Frames, dealt as such, even when they look like channels",
|
|
2846
|
+
"```",
|
|
2847
|
+
"; .N [[1, 3, 5], [2, 4, 6]];",
|
|
2848
|
+
"; [“” (N ./ 2), (N ./ 2).left .0 = [1, 3, 5], (N ./ 2).# , “” ((N ./ 2) ./ 2)]",
|
|
2849
|
+
"# [“RotorRouter([[1, 3, 5]],[[2, 4, 6]])”, <>, 2, “RotorRouter([[1, 3, 5]],[[2, 4, 6]])”]",
|
|
2850
|
+
"```",
|
|
2851
|
+
"Uneven channels read back in dealt order: seven Frames into three channels,",
|
|
2852
|
+
"then into one, give the seven in order; into two they are dealt again from",
|
|
2853
|
+
"that order",
|
|
2854
|
+
"```",
|
|
2855
|
+
"; .Y [1, 2, 3, 4, 5, 6, 7];",
|
|
2856
|
+
"; [“” (Y ./ 3), (((Y ./ 3) ./ 1).channels .0) = Y, “” ((Y ./ 3) ./ 2), ((Y ./ 3) ./ 2) = (Y ./ 2)]",
|
|
2857
|
+
"# [“RotorRouter([[1, 4, 7], [2, 5], [3, 6]])”, <>, “RotorRouter([1, 3, 5, 7],[2, 4, 6])”, <>]",
|
|
2858
|
+
"```",
|
|
2859
|
+
"Channels that no round-robin history left have no dealt order to read, so no",
|
|
2860
|
+
"router holds them and they are not divided: the constructor refuses them, and",
|
|
2861
|
+
"a plain list of such lists is a plain list",
|
|
2862
|
+
"```",
|
|
2863
|
+
"; Routers <- './hc/rotor-router.hc';",
|
|
2864
|
+
"; .RotorRouter Routers.RotorRouter;",
|
|
2865
|
+
"; [RotorRouter [[1], [2, 3]], ([[1], [2, 3]] ./ 2).channels]",
|
|
2866
|
+
"# [$!!.invalid-router, [[[1]], [[2, 3]]]]",
|
|
2867
|
+
"```",
|
|
2868
|
+
"## Refusals",
|
|
2869
|
+
"",
|
|
2870
|
+
"The divisor is a positive Count. Zero is division by zero, and anything else is",
|
|
2871
|
+
"outside the domain, whatever its Size: a negative or fractional number, a",
|
|
2872
|
+
"decimal, text, an aggregate, a Demi. A divisor that is already an error is",
|
|
2873
|
+
"answered as it is",
|
|
2874
|
+
"```",
|
|
2875
|
+
"; [[1, 2] ./ 0, [1, 2] ./ (3 - 1), [1, 2] ./ (0 - 2), [1, 2] ./ (1 / 2), [1, 2] ./ 1.5, [1, 2] ./ “two”, [1, 2] ./ [2]]",
|
|
2876
|
+
"# [$!.division-by-zero /, $!.division-domain /, $!.division-domain /, $!.division-domain /, $!.division-domain /, $!.division-domain /, $!.division-domain /]",
|
|
2877
|
+
"; [1, 2] ./ (1 / 0)",
|
|
2878
|
+
"# $!.division-by-zero /",
|
|
2879
|
+
"; [[1, 2] ./ (2 ** 30), [1, 2] ./ 1000001, ([1] ./ 1000).channels.#]",
|
|
2880
|
+
"# [$!.repetition-size 1000000, $!.repetition-size 1000000, 1000]",
|
|
2881
|
+
"```",
|
|
2882
|
+
"Numbers keep exact numeric division, and a Frame that is neither a number nor",
|
|
2883
|
+
"an ordered list still answers nil",
|
|
2884
|
+
"```",
|
|
2885
|
+
"; [6 ./ 3, 7 ./ 2, 7 / 2, “abcd” ./ 2, <1, 2> ./ 2]",
|
|
2886
|
+
"# [2, 7/2, 7/2, (), ()]",
|
|
2887
|
+
"```",
|
|
2888
|
+
"## Conservation and empty channels",
|
|
2889
|
+
"",
|
|
2890
|
+
"The summed Size of the dealt children is the list's Size: each child is in",
|
|
2891
|
+
"exactly one channel. Each channel's load is the sum of its children's Sizes,",
|
|
2892
|
+
"and an empty channel's load is 0. The router's `.##` is that sum. The `.##`",
|
|
2893
|
+
"of its channels taken as a plain list of lists is not, because an empty array",
|
|
2894
|
+
"has Size 1, so an empty channel adds one",
|
|
2895
|
+
"```",
|
|
2896
|
+
"; .load {.c _; (c.# = 0) ? {0} : {c.##}};",
|
|
2897
|
+
"; .loads {_ & {load _}};",
|
|
2898
|
+
"; [loads ([5, 2] ./ 2).channels, loads ([5, 2] ./ 3).channels, (loads ([5, 2] ./ 3).channels).##, [5, 2].##, ([5, 2] ./ 3).##, ([5, 2] ./ 3).channels.##]",
|
|
2899
|
+
"# [[5, 2], [5, 2, 0], 7, 7, 7, 8]",
|
|
2900
|
+
"```",
|
|
2901
|
+
"Zero-Size children take a slot, and empty children count their own Size 1",
|
|
2902
|
+
"```",
|
|
2903
|
+
"; [loads ([0, 0, 0] ./ 2).channels, loads ([[], [], 0] ./ 2).channels, [[], [], 0].##]",
|
|
2904
|
+
"# [[0, 0], [1, 1], 2]",
|
|
2905
|
+
"```",
|
|
2906
|
+
"Dealing measures nothing, so a child whose Size fails is dealt like any other.",
|
|
2907
|
+
"Its failure shows where the channel is measured",
|
|
2908
|
+
"```",
|
|
2909
|
+
"; .Failing [.## {[].nope}; 1];",
|
|
2910
|
+
"; ([Failing, 1] ./ 2).channels & {_.#}",
|
|
2911
|
+
"# [1, 1]",
|
|
2912
|
+
"; ([Failing, 1] ./ 2).##",
|
|
2913
|
+
"# $!.name-missing “...",
|
|
2914
|
+
"```",
|
|
2915
|
+
"## Demi",
|
|
2916
|
+
"",
|
|
2917
|
+
"A Demi of any arity is `Demi [C, loads]`, a Count and a nonempty list of",
|
|
2918
|
+
"Counts. Two loads are the binary Demi `Demi [C, L, R]` itself, the same",
|
|
2919
|
+
"instance, with its `left`, `right` and `phase`; any other arity is a channel",
|
|
2920
|
+
"Demi, which reads as `Demi(C,[…])`. Every Demi stores `count` and `loads`",
|
|
2921
|
+
"```",
|
|
2922
|
+
"; Demis <- './hc/demi.hc';",
|
|
2923
|
+
"; .Demi Demis.Demi;",
|
|
2924
|
+
"; [“” (Demi [3, [5, 2]]), (Demi [3, [5, 2]]) == (Demi [3, 5, 2]), (Demi [3, [5, 2]]).left, (Demi [3, 5, 2]).loads]",
|
|
2925
|
+
"# [“Demi(3,5,2)”, <>, 5, [5, 2]]",
|
|
2926
|
+
"; [“” (Demi [0, [0, 0, 0]]), “” (Demi [4, [7]]), “” (Demi [2, [1, 2, 3, 4]]), (Demi [2, [1, 2, 3]]).loads, (Demi [2, [1, 2, 3]]).count]",
|
|
2927
|
+
"# [“Demi(0,[0, 0, 0])”, “Demi(4,[7])”, “Demi(2,[1, 2, 3, 4])”, [1, 2, 3], 2]",
|
|
2928
|
+
"```",
|
|
2929
|
+
"No channels, a load that is not a Count, and any other shape are refused",
|
|
2930
|
+
"```",
|
|
2931
|
+
"; [Demi [2, []], Demi [2, [1, (0 - 1), 3]], Demi [2, [1, 1.5]], Demi [2, [1, [2]]], Demi [(0 - 2), [1]], Demi [2, 5], Demi [2, [1], 3], Demi [2, [1, 2], 3, 4]]",
|
|
2932
|
+
"# [$!!.invalid-demi, $!!.invalid-demi, $!!.invalid-demi, $!!.invalid-demi, $!!.invalid-demi, $!!.invalid-demi, $!!.invalid-demi, $!!.invalid-demi]",
|
|
2933
|
+
"```",
|
|
2934
|
+
"A channel Demi observes as its loads do: its Count is C, its Size the sum of",
|
|
2935
|
+
"its loads, and its residual their alternating sum, `e0 − e1 + e2 − …`, the",
|
|
2936
|
+
"list residual, which for two loads is `L − R`",
|
|
2937
|
+
"```",
|
|
2938
|
+
"; .d7 (Demi [3, 5, 2]); .q3 (d7 ./ 3);",
|
|
2939
|
+
"; [q3.#, q3.##, q3.###, q3.count, q3.loads]",
|
|
2940
|
+
"# [3, 7, 3, 3, [3, 2, 2]]",
|
|
2941
|
+
"```",
|
|
2942
|
+
"## Demi division redistributes Size units",
|
|
2943
|
+
"",
|
|
2944
|
+
"`D ./ n` keeps the Count and the Size and deals the Size units round-robin into",
|
|
2945
|
+
"n channels. For S = 7: into 2, 4 and 3; into 3, 3, 2 and 2; into 4, 2, 2, 2",
|
|
2946
|
+
"and 1. Into one channel it is the whole Size, and into more channels than units",
|
|
2947
|
+
"the last are empty",
|
|
2948
|
+
"```",
|
|
2949
|
+
"; [“” (d7 ./ 2), “” (d7 ./ 3), “” (d7 ./ 4), “” (d7 ./ 1), “” (d7 ./ 9)]",
|
|
2950
|
+
"# [“Demi(3,4,3)”, “Demi(3,[3, 2, 2])”, “Demi(3,[2, 2, 2, 1])”, “Demi(3,[7])”, “Demi(3,[1, 1, 1, 1, 1, 1, 1, 0, 0])”]",
|
|
2951
|
+
"```",
|
|
2952
|
+
"`Demi(3,[5,2]) ./ 3` is `Demi(3,[3,2,2])`, and so is the different state",
|
|
2953
|
+
"`Demi(3,[4,3]) ./ 3`. Normalization is many-to-one: equal Count and Size give",
|
|
2954
|
+
"the same result, and the original distribution cannot be recovered",
|
|
2955
|
+
"```",
|
|
2956
|
+
"; [q3 = (Demi [3, [3, 2, 2]]), ((Demi [3, 4, 3]) ./ 3) = q3, (Demi [3, 4, 3]) = d7, (d7 / 3) = q3, q3 = d7]",
|
|
2957
|
+
"# [<>, <>, (), <>, ()]",
|
|
2958
|
+
"```",
|
|
2959
|
+
"It is idempotent, and dividing again renormalizes from the same Count and Size,",
|
|
2960
|
+
"so the earlier division leaves no trace",
|
|
2961
|
+
"```",
|
|
2962
|
+
"; [(q3 ./ 3) = q3, (q3 ./ 2) = (d7 ./ 2), ((d7 ./ 4) ./ 3) = q3, “” (q3 ./ 2), ((q3 ./ 2) ./ 3) = q3]",
|
|
2963
|
+
"# [<>, <>, <>, “Demi(3,4,3)”, <>]",
|
|
2964
|
+
"```",
|
|
2965
|
+
"Zero Size, zero Count, one channel, and more channels than Size or Count",
|
|
2966
|
+
"```",
|
|
2967
|
+
"; [“” ((Demi [0, 0, 0]) ./ 3), “” ((Demi [0, 9, 0]) ./ 4), “” ((Demi [0, 9, 0]) ./ 1), “” ((Demi [2, 1, 1]) ./ 5), “” ((Demi [1, 0, 0]) ./ 2)]",
|
|
2968
|
+
"# [“Demi(0,[0, 0, 0])”, “Demi(0,[3, 2, 2, 2])”, “Demi(0,[9])”, “Demi(2,[1, 1, 0, 0, 0])”, “Demi(1,0,0)”]",
|
|
2969
|
+
"```",
|
|
2970
|
+
"The divisor is a channel Count, refused as a list refuses it, never coerced to",
|
|
2971
|
+
"its Size",
|
|
2972
|
+
"```",
|
|
2973
|
+
"; [d7 ./ 0, d7 ./ (3 - 1), d7 ./ 1.5, d7 ./ (1 / 2), d7 ./ [3], d7 ./ “three”, d7 ./ (Demi [1, 1, 1])]",
|
|
2974
|
+
"# [$!.division-by-zero /, $!.division-domain /, $!.division-domain /, $!.division-domain /, $!.division-domain /, $!.division-domain /, $!.division-domain /]",
|
|
2975
|
+
"```",
|
|
2976
|
+
"## Applying after division",
|
|
2977
|
+
"",
|
|
2978
|
+
"After `./ n` the next application deposits into channel C mod n and adds one to",
|
|
2979
|
+
"the Count, a Size of zero included. `q3` has Count 3, so it deposits into",
|
|
2980
|
+
"channels 0, 1, 2, 0 in turn",
|
|
2981
|
+
"```",
|
|
2982
|
+
"; [“” (q3 10), “” ((q3 10) 1), “” (((q3 10) 1) 1), “” ((((q3 10) 1) 1) 1)]",
|
|
2983
|
+
"# [“Demi(4,[13, 2, 2])”, “Demi(5,[13, 3, 2])”, “Demi(6,[13, 3, 3])”, “Demi(7,[14, 3, 3])”]",
|
|
2984
|
+
"; [“” ((Demi [0, [0, 0, 0]]) 4), “” (((Demi [0, [0, 0, 0]]) 4) 0), “” ((((Demi [0, [0, 0, 0]]) 4) 0) 6)]",
|
|
2985
|
+
"# [“Demi(1,[4, 0, 0])”, “Demi(2,[4, 0, 0])”, “Demi(3,[4, 0, 6])”]",
|
|
2986
|
+
"```",
|
|
2987
|
+
"A reduce applies it the same way, and through a mutable name it writes in",
|
|
2988
|
+
"place. One channel takes every deposit, and two channels are the binary Demi's",
|
|
2989
|
+
"parity",
|
|
2990
|
+
"```",
|
|
2991
|
+
"; “” ([5, 2, 7, 1, 0] | (Demi [0, [0, 0, 0]]))",
|
|
2992
|
+
"# “Demi(5,[6, 2, 7])”",
|
|
2993
|
+
"; .m_ (Demi [0, [0, 0, 0]]);",
|
|
2994
|
+
"; m_ 5;",
|
|
2995
|
+
"; m_ 6;",
|
|
2996
|
+
"; [“” m_, “” ((d7 ./ 1) 4), “” ((d7 ./ 2) 4), “” (d7 4)]",
|
|
2997
|
+
"# [“Demi(2,[5, 6, 0])”, “Demi(4,[11])”, “Demi(4,4,7)”, “Demi(4,5,6)”]",
|
|
2998
|
+
"```",
|
|
2999
|
+
"## Demi laws",
|
|
3000
|
+
"",
|
|
3001
|
+
"For every Count 0 to 3, every pair of loads 0 to 4 (100 states) and every n",
|
|
3002
|
+
"from 1 to 4: the Count and Size are kept, there are n loads, they are the",
|
|
3003
|
+
"dealing of S unit Frames into n channels, division is idempotent, and for every",
|
|
3004
|
+
"m from 1 to 4 dividing by n then m is dividing by m",
|
|
3005
|
+
"```",
|
|
3006
|
+
"; .cs [0, 1, 2, 3]; .ls [0, 1, 2, 3, 4]; .ns [1, 2, 3, 4];",
|
|
3007
|
+
"; .states (cs &| {.c _; ls &| {.l _; ls & {Demi [c, l, _]}}});",
|
|
3008
|
+
"; .law {.k _; ns &| {.n _; .q (k ./ n); [q.# = k.#, q.## = k.##, q.loads.# = n, q.loads = (((k.## [1]) ./ n).channels & {_.#}), (q ./ n) = q]}};",
|
|
3009
|
+
"; .renorm {.k _; ns &| {.n _; ns & {.m _; ((k ./ n) ./ m) = (k ./ m)}}};",
|
|
3010
|
+
"; .checks ((states &| law) | (states &| renorm));",
|
|
3011
|
+
"; [states.#, checks.#, checks = (checks & {<>})]",
|
|
3012
|
+
"# [100, 3600, <>]",
|
|
3013
|
+
"```",
|
|
3014
|
+
"## Channel Demi operations",
|
|
3015
|
+
"",
|
|
3016
|
+
"Its fourth hash is intrinsic, as for the binary Demi: a fresh equal channel Demi",
|
|
3017
|
+
"of the same arity, Count zero included. A record that only spells the fields is",
|
|
3018
|
+
"not one, and forged observers give the ordinary derived binary Demi",
|
|
3019
|
+
"```",
|
|
3020
|
+
"; [(q3.####) == q3, (q3.####) === q3, ((Demi [0, [0, 0, 0]]).####) = (Demi [0, [0, 0, 0]]), ([5, 2].#### ./ 3) = (Demi [2, [3, 2, 2]])]",
|
|
3021
|
+
"# [<>, (), <>, <>]",
|
|
3022
|
+
"; [[.count 3; .loads [3, 2, 2]].####, “” ([.count 3; .loads [3, 2, 2]; .# {3}; .## {7}; .### {3}].####)]",
|
|
3023
|
+
"# [(), “Demi(3,5,2)”]",
|
|
3024
|
+
"```",
|
|
3025
|
+
"`*` and `scale_` scale every load and keep the Count; the ratios read Size and",
|
|
3026
|
+
"residual over the Count, nil at Count zero",
|
|
3027
|
+
"```",
|
|
3028
|
+
"; [“” (q3 * 2), “” (q3.scale_ 3), q3.size-ratio (), q3.residual-ratio (), (Demi [0, [3, 2, 2]]).size-ratio ()]",
|
|
3029
|
+
"# [“Demi(3,[6, 4, 4])”, “Demi(3,[9, 6, 6])”, 7/3, 1, ()]",
|
|
3030
|
+
"```",
|
|
3031
|
+
"`+` and `-` follow the residual's signs. The residual adds the loads at even",
|
|
3032
|
+
"indices and subtracts those at odd ones, so `-` deposits `x.##` on the first",
|
|
3033
|
+
"even load, load 0, and raises the residual, and `+` deposits on the first odd",
|
|
3034
|
+
"load, load 1, and lowers it. For two loads these are the binary Demi's left and",
|
|
3035
|
+
"right. Both keep the Count, and both are `deposit-left_` and `deposit-right_`",
|
|
3036
|
+
"by the operand's Size. One load has no odd index, so there `+` is",
|
|
3037
|
+
"`$!!.invalid-arity`",
|
|
3038
|
+
"```",
|
|
3039
|
+
"; [“” (q3 + 1), “” (q3 - 1), q3.###, (q3 + 1).###, (q3 - 1).###, (q3 + 1).#]",
|
|
3040
|
+
"# [“Demi(3,[3, 3, 2])”, “Demi(3,[4, 2, 2])”, 3, 2, 4, 3]",
|
|
3041
|
+
"; [“” ((d7 ./ 4) + 1), “” ((d7 ./ 4) - 2.5), (d7 ./ 1) + 1, “” ((d7 ./ 1) - 1), “” (d7 + 1), “” (d7 - 1)]",
|
|
3042
|
+
"# [“Demi(3,[2, 3, 2, 1])”, “Demi(3,[4, 2, 2, 1])”, $!!.invalid-arity, “Demi(3,[8])”, “Demi(3,5,3)”, “Demi(3,6,2)”]",
|
|
3043
|
+
"; [((q3 + 4) - 2) = ((q3 - 2) + 4), ((q3 + 1) ./ 3) = ((q3 - 1) ./ 3), q3 + ([].nope), q3.deposit-right_ (0 - 1), q3.deposit-left_ 1.5, “” q3]",
|
|
3044
|
+
"# [<>, <>, $!.name-missing “..., $!!.invalid-demi, $!!.invalid-demi, “Demi(3,[3, 2, 2])”]",
|
|
3045
|
+
"```",
|
|
3046
|
+
"## RotorRouter",
|
|
3047
|
+
"",
|
|
3048
|
+
"`RotorRouter [ch0, …, chk−1]` takes k ≥ 1 channel arrays. Two are the binary",
|
|
3049
|
+
"router, with its `left`, `right` and `phase`; every router stores `channels`.",
|
|
3050
|
+
"A round-robin history from channel 0 fills the channels so that the first",
|
|
3051
|
+
"C mod k hold one more than the rest, so the constructor admits exactly the",
|
|
3052
|
+
"channels whose Counts are the dealing of C into k, and refuses every other",
|
|
3053
|
+
"```",
|
|
3054
|
+
"; [[[]], [[], []], [[], [], []], [[], [], [], []]] & {“” (RotorRouter _)}",
|
|
3055
|
+
"# [“RotorRouter([[]])”, “RotorRouter([],[])”, “RotorRouter([[], [], []])”, “RotorRouter([[], [], [], []])”]",
|
|
3056
|
+
"; [[[5]], [[5], [6]], [[5], [], []], [[5], [6], []], [[5, 8], [6], [7]], [[5, 9], [6], [7], [8]]] & {(RotorRouter _).#}",
|
|
3057
|
+
"# [1, 2, 1, 2, 4, 5]",
|
|
3058
|
+
"; [RotorRouter [[1], [2], [3, 4]], RotorRouter [[1], [], [2]], RotorRouter [[1, 2, 3], [4], [5]], RotorRouter [[], [1]], RotorRouter [[1, 2], [3], [4], [5], [6, 7]], RotorRouter []]",
|
|
3059
|
+
"# [$!!.invalid-router, $!!.invalid-router, $!!.invalid-router, $!!.invalid-router, $!!.invalid-router, $!!.invalid-router]",
|
|
3060
|
+
"```",
|
|
3061
|
+
"Routing appends the Frame to channel C mod k, from Count 0 through 6 here, so",
|
|
3062
|
+
"every successor is admissible again. Routing nil routes nothing",
|
|
3063
|
+
"```",
|
|
3064
|
+
"; .s0 (RotorRouter [[], [], []]);",
|
|
3065
|
+
"; [0, 1, 2, 3, 4, 5, 6] & {.n _; ((n [0]) | s0).channels & {_.#}}",
|
|
3066
|
+
"# [[0, 0, 0], [1, 0, 0], [1, 1, 0], [1, 1, 1], [2, 1, 1], [2, 2, 1], [2, 2, 2]]",
|
|
3067
|
+
"; [“” ((s0 A) B), (((s0 A) B) C).channels .2 &| {[_ === C]}, (s0 ()).#]",
|
|
3068
|
+
"# [“RotorRouter([[[1, [2]]], [“b”], []])”, [<>], 0]",
|
|
3069
|
+
"```",
|
|
3070
|
+
"## Router division re-deals the Frames",
|
|
3071
|
+
"",
|
|
3072
|
+
"Routing xs from the initial router, then dividing by 3, is the router of",
|
|
3073
|
+
"`xs ./ 3`: the router's history is reconstructed from its channels and dealt",
|
|
3074
|
+
"again. The Count and the summed Size are kept, every Frame is the same Frame,",
|
|
3075
|
+
"and dividing by one gives the history back in routed order",
|
|
3076
|
+
"```",
|
|
3077
|
+
"; .r0 (RotorRouter [[], []]);",
|
|
3078
|
+
"; .r7 (xs | r0); .t3 (r7 ./ 3);",
|
|
3079
|
+
"; [“” t3, t3.channels & {_.#}, t3.# = r7.#, t3.## = r7.##, t3 = (xs ./ 3)]",
|
|
3080
|
+
"# [“RotorRouter([[[1, [2]], [.k 9; 4], 7], [“b”, 5], [{ 5 + 3 }, (6, 7)]])”, [3, 2, 2], <>, <>, <>]",
|
|
3081
|
+
"; [(t3.channels .0) &| {[_ === A]}, (t3.channels .2) &| {[_ === C]}, ((t3.channels .0) .1).k, ((t3 ./ 1).channels .0) = xs]",
|
|
3082
|
+
"# [[<>, (), ()], [<>, ()], 9, <>]",
|
|
3083
|
+
"```",
|
|
3084
|
+
"Division is idempotent and renormalizes: dividing again re-deals the same",
|
|
3085
|
+
"history, so a router divided by 3 and then 2 is the binary router it came",
|
|
3086
|
+
"from. The empty router divides into empty channels",
|
|
3087
|
+
"```",
|
|
3088
|
+
"; [(t3 ./ 3) = t3, (t3 ./ 2) = r7, ((r7 ./ 4) ./ 3) = t3, ((t3 ./ 4) ./ 2) = r7, “” (r0 ./ 3), (r0 ./ 3).#, ((RotorRouter [[], [], []]) ./ 2) = r0]",
|
|
3089
|
+
"# [<>, <>, <>, <>, “RotorRouter([[], [], []])”, 0, <>]",
|
|
3090
|
+
"```",
|
|
3091
|
+
"After division the next route goes to channel C mod n: `t3` has Count 7, so 8,",
|
|
3092
|
+
"9 and 10 go to channels 1, 2 and 0. Divided back into two, it is the binary",
|
|
3093
|
+
"router that routed the same Frames",
|
|
3094
|
+
"```",
|
|
3095
|
+
"; [“” (t3 8), “” ((t3 8) 9), “” (((t3 8) 9) 10)]",
|
|
3096
|
+
"# [“RotorRouter([[[1, [2]], [.k 9; 4], 7], [“b”, 5, 8], [{ 5 + 3 }, (6, 7)]])”, “RotorRouter([[[1, [2]], [.k 9; 4], 7], [“b”, 5, 8], [{ 5 + 3 }, (6, 7), 9]])”, “RotorRouter([[[1, [2]], [.k 9; 4], 7, 10], [“b”, 5, 8], [{ 5 + 3 }, (6, 7), 9]])”]",
|
|
3097
|
+
"; [((t3 8) ./ 2) = (r7 8), (((t3 8) 9) ./ 1).channels .0 = ((xs 8) 9)]",
|
|
3098
|
+
"# [<>, <>]",
|
|
3099
|
+
"```",
|
|
3100
|
+
"Division routes and measures nothing. A Frame held through a mutable name is",
|
|
3101
|
+
"the same Frame after division, so a later write shows; a child whose Size",
|
|
3102
|
+
"fails is re-dealt and fails only where the router is measured; zero-Size",
|
|
3103
|
+
"children and empty arrays take slots, and nested arrays stay whole",
|
|
3104
|
+
"```",
|
|
3105
|
+
"; .kid_ [.n 1; .set_ {@n _;}];",
|
|
3106
|
+
"; .rk ((r0 kid_) ./ 3);",
|
|
3107
|
+
"; kid_.set_ 5;",
|
|
3108
|
+
"; [(rk.channels .0 .0) === kid_, rk.channels .0 .0 .n]",
|
|
3109
|
+
"# [<>, 5]",
|
|
3110
|
+
"; .rf (((r0 Failing) 0) ./ 3);",
|
|
3111
|
+
"; [rf.channels & {_.#}, ((r0 Failing) ./ 3) = (RotorRouter [[Failing], [], []])]",
|
|
3112
|
+
"# [[1, 1, 0], <>]",
|
|
3113
|
+
"; rf.##",
|
|
3114
|
+
"# $!.name-missing “...",
|
|
3115
|
+
"; .rz ((((r0 0) []) <>) ./ 2);",
|
|
3116
|
+
"; [rz.channels, rz.##, rz.###]",
|
|
3117
|
+
"# [[[0, <>], [[]]], 2, 0]",
|
|
3118
|
+
"; [((RotorRouter [[[1, 2]], [[3]]]) ./ 1).channels, ((RotorRouter [[[1, 2]], [[3]]]) ./ 1).## = (RotorRouter [[[1, 2]], [[3]]]).##]",
|
|
3119
|
+
"# [[[[1, 2], [3]]], <>]",
|
|
3120
|
+
"```",
|
|
3121
|
+
"A router's history is not bounded by the channel limit: its readout divides by",
|
|
3122
|
+
"its longest channel's length, which never exceeds the Frames it holds, so a",
|
|
3123
|
+
"one-channel router of 1,000,001 Frames divides into two (PR #482 review)",
|
|
3124
|
+
"```",
|
|
3125
|
+
"; .big ((500001 [1]) | (500000 [1]));",
|
|
3126
|
+
"; [big.#, ((RotorRouter [big]) ./ 2).channels & {_.#}]",
|
|
3127
|
+
"# [1000001, [500001, 500000]]",
|
|
3128
|
+
"```",
|
|
3129
|
+
"Routing appends to channel C mod k directly, without replaying the history, so",
|
|
3130
|
+
"routing grows linearly: three thousand Frames route into three channels in turn",
|
|
3131
|
+
"```",
|
|
3132
|
+
"; .grown ((3000 [1]) | (RotorRouter [[], [], []]));",
|
|
3133
|
+
"; [grown.#, grown.channels & {_.#}, (grown ./ 3) = grown, ((grown ./ 1).channels .0).# ]",
|
|
3134
|
+
"# [3000, [1000, 1000, 1000], <>, 3000]",
|
|
3135
|
+
"```",
|
|
3136
|
+
"The divisor is refused as for a list",
|
|
3137
|
+
"```",
|
|
3138
|
+
"; [r7 ./ 0, r7 ./ (3 - 1), r7 ./ 1.5, r7 ./ [2], r7 ./ (Demi [1, 1, 1]), r7 ./ “two”]",
|
|
3139
|
+
"# [$!.division-by-zero /, $!.division-domain /, $!.division-domain /, $!.division-domain /, $!.division-domain /, $!.division-domain /]",
|
|
3140
|
+
"```",
|
|
3141
|
+
"## A router's observers and fourth hash",
|
|
3142
|
+
"",
|
|
3143
|
+
"A router of any arity declares its Count C, its Size, the sum of its channel",
|
|
3144
|
+
"loads, and its residual, their alternating sum, as a channel Demi does. Its",
|
|
3145
|
+
"fourth hash is the Demi of the same arity: a router of k channels other than",
|
|
3146
|
+
"two is recognized intrinsically, as an instance of the shipped class, and",
|
|
3147
|
+
"answers `Demi [C, loads]`, one load per channel, so it routes to channel",
|
|
3148
|
+
"C mod k as its Demi deposits there. The binary router answers the binary Demi",
|
|
3149
|
+
"it always did. At Count zero there is no Demi, for any arity",
|
|
3150
|
+
"```",
|
|
3151
|
+
"; [t3.#, t3.##, t3.###, “” t3.####, t3.#### = (Demi [7, [14, 6, 22]]), t3.####.## = t3.##, t3.####.### = t3.###]",
|
|
3152
|
+
"# [7, 42, 30, “Demi(7,[14, 6, 22])”, <>, <>, <>]",
|
|
3153
|
+
"; [“” (r7.####), ([] ./ 3).####, (RotorRouter [[], [], []]).####, “” ((([] ./ 3) 5).####)]",
|
|
3154
|
+
"# [“Demi(7,24,18)”, (), (), “Demi(1,[5, 0, 0])”]",
|
|
3155
|
+
"```",
|
|
3156
|
+
"So the projection law `(r y).#### = r.#### y` holds for every arity: routing y",
|
|
3157
|
+
"to channel C mod k and observing is depositing `y.##` there",
|
|
3158
|
+
"```",
|
|
3159
|
+
"; .nine [1, 2, 3, 4, 5, 6, 7, 8, 9];",
|
|
3160
|
+
"; [1, 2, 3, 4, 5] & {.r (nine ./ _); ((r 10).####) = ((r.####) 10)}",
|
|
3161
|
+
"# [<>, <>, <>, <>, <>]",
|
|
3162
|
+
"; [“” ((t3 10).####), “” ((nine ./ 1).####), “” ((nine ./ 4).####)]",
|
|
3163
|
+
"# [“Demi(8,[14, 16, 22])”, “Demi(9,[45])”, “Demi(9,[15, 8, 10, 12])”]",
|
|
3164
|
+
"```",
|
|
3165
|
+
"Recognition reads nothing the router computes: a record that only spells",
|
|
3166
|
+
"`channels` is not a router, and a failed child Size is answered as it is",
|
|
3167
|
+
"```",
|
|
3168
|
+
"; [[.channels [[1], [], []]].####, ([Failing] ./ 3).####]",
|
|
3169
|
+
"# [(), $!.name-missing “...]",
|
|
3170
|
+
"```",
|
|
3171
|
+
"## Whole Frames and Size units",
|
|
3172
|
+
"",
|
|
3173
|
+
"Whole-Frame division and Size-unit division agree on the total and differ on",
|
|
3174
|
+
"the channels. Children of Sizes 5 and 2 dealt into two channels load them 5",
|
|
3175
|
+
"and 2, as list and router; the Demi of the same list, normalized, loads them 4",
|
|
3176
|
+
"and 3. They are different states with the same Size, and neither is wrong",
|
|
3177
|
+
"```",
|
|
3178
|
+
"; .two [5, 2];",
|
|
3179
|
+
"; [loads (two ./ 2).channels, ((two | r0) ./ 2).channels & {load _}, “” (two.#### ./ 2), ((two | r0) ./ 2).#### = (two.#### ./ 2), ((two | r0) ./ 2).####.## = (two.#### ./ 2).##]",
|
|
3180
|
+
"# [[5, 2], [5, 2], “Demi(2,4,3)”, (), <>]",
|
|
3181
|
+
"```",
|
|
3182
|
+
"They agree when every child has Size one, since then each Frame is one Size",
|
|
3183
|
+
"unit. With other Sizes they need not",
|
|
3184
|
+
"```",
|
|
3185
|
+
"; .ones [1, 1, 1, 1, 1, 1, 1];",
|
|
3186
|
+
"; [((ones | r0) ./ 3).channels & {load _}, (ones.#### ./ 3).loads, loads ([5, 2, 9, 1] ./ 3).channels, ([5, 2, 9, 1].#### ./ 3).loads]",
|
|
3187
|
+
"# [[3, 2, 2], [3, 2, 2], [6, 2, 9], [6, 6, 5]]",
|
|
3188
|
+
"",
|
|
3189
|
+
].join("\n"),
|
|
3190
|
+
],
|
|
2192
3191
|
[
|
|
2193
3192
|
"hc/figures.hc",
|
|
2194
3193
|
[
|
|
@@ -3093,7 +4092,8 @@ export const HC_SOURCES = new Map([
|
|
|
3093
4092
|
"array's properties are configuration, not routed Frames, so the constructor",
|
|
3094
4093
|
"keeps the elements in a fresh array of its own, counts them there, and a",
|
|
3095
4094
|
"channel argument that declares `apply` cannot change what appending means.",
|
|
3096
|
-
"Anything that is not
|
|
4095
|
+
"Anything that is not a nonempty list of arrays is refused the same way; one",
|
|
4096
|
+
"array or three are routers of another arity (below).",
|
|
3097
4097
|
"",
|
|
3098
4098
|
"**Routing**, `router x`: append x as one member of the channel the parity of C",
|
|
3099
4099
|
"selects; the Count grows by one and the phase flips with it. `router.phase` is",
|
|
@@ -3134,25 +4134,93 @@ export const HC_SOURCES = new Map([
|
|
|
3134
4134
|
"`RotorRouter([…],[…])`, each channel as its spelling, the constructor's own",
|
|
3135
4135
|
"shape.",
|
|
3136
4136
|
"",
|
|
4137
|
+
"**Channels and division (007.27).** Two channels are the arity-two case of k",
|
|
4138
|
+
"ordered channels. `RotorRouter [ch0, …, chk−1]` takes k ≥ 1 arrays; two are",
|
|
4139
|
+
"this binary router, and any other number is a channel router. Every router",
|
|
4140
|
+
"stores `channels`; only the binary one also has `left`, `right` and `phase`,",
|
|
4141
|
+
"which it writes together with `channels`. A round-robin history from channel 0",
|
|
4142
|
+
"leaves the first C mod k channels one longer than the rest, so a channel",
|
|
4143
|
+
"router admits exactly the channels whose Counts are the dealing of C children",
|
|
4144
|
+
"into k, `round-robin [C, k]`, and refuses every other with",
|
|
4145
|
+
"`$!!.invalid-router`.",
|
|
4146
|
+
"Routing appends to channel C mod k, which for k = 2 is the phase's channel,",
|
|
4147
|
+
"directly, as the binary router does: a small cursor, `append-at`, rebuilds the",
|
|
4148
|
+
"list of channels with the Frame added to that one, so a route costs one pass",
|
|
4149
|
+
"over the k channels and never replays the history (PR #482 review).",
|
|
4150
|
+
"Its Size is the sum of its channel loads and its residual their alternating",
|
|
4151
|
+
"sum, as a channel Demi's are. Its fourth hash is the channel Demi of its",
|
|
4152
|
+
"Count and channel loads, `Demi [C, [load0, …]]`: the fourth hash recognizes an",
|
|
4153
|
+
"instance of this class with other than two channels intrinsically, as it",
|
|
4154
|
+
"recognizes a Demi, because the binary Demi the observers derive follows",
|
|
4155
|
+
"parity and not C mod k. So the projection law `(r y).#### = r.#### y` holds",
|
|
4156
|
+
"for every arity; at Count zero there is no Demi. Text reads `RotorRouter([ch0, ch1, …])`.",
|
|
4157
|
+
"",
|
|
4158
|
+
"`router ./ n`, also spelled `router / n`, re-deals the Frames it holds: it",
|
|
4159
|
+
"reconstructs the order they were routed in from its channels, which their",
|
|
4160
|
+
"admissibility fixes, and routes that history through a fresh router of n",
|
|
4161
|
+
"channels, that is, it is the history divided as a list, `history / n`, since",
|
|
4162
|
+
"list division answers the n-channel router of its channels (007.27c).",
|
|
4163
|
+
"Reconstructing the history is the breadth-first readout of 007.27c: the first",
|
|
4164
|
+
"Frame of each channel in channel order, then the second of each, and so on. Every Frame stays the",
|
|
4165
|
+
"same Frame, whole, in order, exactly once, and nothing is evaluated or",
|
|
4166
|
+
"measured; the Count is kept and the next route goes to channel C mod n. The",
|
|
4167
|
+
"history is the dealing inverted: the channels, the short ones padded with a",
|
|
4168
|
+
"sentinel to the longest, are concatenated and dealt into that many channels,",
|
|
4169
|
+
"which are the rounds, and the sentinels removed. One channel is its own",
|
|
4170
|
+
"history, and channels of equal length need no sentinel. The readout divides by",
|
|
4171
|
+
"the longest channel's length, which never exceeds the Frames held, so it is",
|
|
4172
|
+
"never refused by the channel limit. The divisor is refused as a list refuses",
|
|
4173
|
+
"it. `hc/division.hc` is its specification.",
|
|
4174
|
+
"",
|
|
3137
4175
|
"**Methods read their own state through `_^`.** A router is applied to",
|
|
3138
4176
|
"arbitrary Frames, and a bare name in a method is looked up on the argument",
|
|
3139
4177
|
"first (spec 7), so a router reads its fields through the receiver, `_^` from",
|
|
3140
|
-
"the method body. What a branch needs is bound as a local at method level.",
|
|
4178
|
+
"the method body. What a branch needs is bound as a local at method level. The",
|
|
4179
|
+
"file's own names, `RotorRouter` and `history`, are read through the scope a",
|
|
4180
|
+
"caret ladder reaches, `(_^^ .history)` from the method body, so an argument's",
|
|
4181
|
+
"fields never stand in for them.",
|
|
3141
4182
|
"```",
|
|
3142
4183
|
".channel-load {.c _; (c.# = 0) ? {0} : {c.##}};",
|
|
3143
|
-
".
|
|
3144
|
-
" (
|
|
3145
|
-
"
|
|
3146
|
-
" .
|
|
4184
|
+
".history {.cs _; .k (cs.#); .w ((cs .0).#); .pad [];",
|
|
4185
|
+
" (k = 1) ? {cs .0} : {(w = 0) ? {[]} : {",
|
|
4186
|
+
" .even ((((cs &| {_}).#) = (k * w)) ? {1} : {0});",
|
|
4187
|
+
" .padded ((even = 1) ? {cs} : {cs & {.ch _; (ch.# = w) ? {ch} : {ch pad}}});",
|
|
4188
|
+
" .flat ((((padded &| {_}) / w) .channels) &| {_});",
|
|
4189
|
+
" (even = 1) ? {flat} : {flat &| {.x _; (x === (_^^^^ .pad)) ? {[]} : {[x]}}}}}};",
|
|
4190
|
+
".append-at {.at (_ .0); .item (_ .1); [.index 0; .target at; .item item; .out [];",
|
|
4191
|
+
" .apply_ {.v _; .i (_^ .index); .t (_^ .target); .it (_^ .item); .o (_^ .out);",
|
|
4192
|
+
" @out (o ((i = t) ? {it | v} : {v})); @index (i + 1);}]};",
|
|
4193
|
+
".round-robin {.s (_ .0); .ways (_ .1); .q (((s - (s %% ways)) / ways).##);",
|
|
4194
|
+
" [.low q; .short 0; .ok 1;",
|
|
4195
|
+
" .apply_ {.c _; .lo (_^ .low); .seen (_^ .short); .fine (_^ .ok);",
|
|
4196
|
+
" @ok ((((c = (lo + 1)) ? {seen = 0} : {c = lo}) ? {fine = 1}) ? {1} : {0}); @short ((c = lo) ? {1} : {seen});}]};",
|
|
4197
|
+
".binary-router {.cs _; .lc (cs .0); .rc (cs .1); [",
|
|
4198
|
+
" .phase (((lc.#) = (rc.#)) ? {2} : {1});",
|
|
3147
4199
|
" .left lc;",
|
|
3148
4200
|
" .right rc;",
|
|
4201
|
+
" .channels [lc, rc];",
|
|
3149
4202
|
" .apply_ {.x _; .l (_^ .left); .r (_^ .right); .n (l.# + r.#);",
|
|
3150
|
-
" ((n %% 2) = 0) ? {
|
|
4203
|
+
" ((n %% 2) = 0) ? {.nl (l x); @left nl; @channels [nl, r]; @phase 1;} : {.nr (r x); @right nr; @channels [l, nr]; @phase 2;};};",
|
|
3151
4204
|
" .# {.l (_^ .left); .r (_^ .right); l.# + r.#};",
|
|
3152
4205
|
" .## {(channel-load (_^ .left)) + (channel-load (_^ .right))};",
|
|
3153
4206
|
" .### {(channel-load (_^ .left)) - (channel-load (_^ .right))};",
|
|
4207
|
+
" ./ {.ways _; ((_^^ .history) (_^ .channels)) / ways};",
|
|
3154
4208
|
" .toText {“RotorRouter(” (_^ .left) “,” (_^ .right) “)”}",
|
|
3155
|
-
" ]}
|
|
4209
|
+
" ]};",
|
|
4210
|
+
".channel-router {.cs _; [",
|
|
4211
|
+
" .channels cs;",
|
|
4212
|
+
" .apply_ {.x _; .cs (_^ .channels); .n ((cs & {_.#}).##);",
|
|
4213
|
+
" @channels ((cs | ((_^^ .append-at) [(n %% (cs.#)), [x]])) .out);};",
|
|
4214
|
+
" .# {((_^ .channels) &| {_}).#};",
|
|
4215
|
+
" .## {((_^ .channels) & {channel-load _}).##};",
|
|
4216
|
+
" .### {((_^ .channels) & {channel-load _}).###};",
|
|
4217
|
+
" ./ {.ways _; ((_^^ .history) (_^ .channels)) / ways};",
|
|
4218
|
+
" .toText {“RotorRouter(” (_^ .channels) “)”}",
|
|
4219
|
+
" ]};",
|
|
4220
|
+
".RotorRouter {((_ ~ ([].<>)) ? {(__ .#) .> 0}) ? {.a __;",
|
|
4221
|
+
" ((a &| {.x _; (x ~ ([].<>)) ? {[]} : {[x]}}).# = 0) ? {.cs (a & {_ | []}); .k (cs.#); .n ((cs &| {_}).#);",
|
|
4222
|
+
" ((k .> 0) ? {(((cs & {_.#}) | (round-robin [n, k])) .ok) = 1}) ? {(k = 2) ? {binary-router cs} : {channel-router cs}} : {$!!.invalid-router}",
|
|
4223
|
+
" } : {$!!.invalid-router}} : {$!!.invalid-router}};",
|
|
3156
4224
|
"```",
|
|
3157
4225
|
"## Construction",
|
|
3158
4226
|
"",
|
|
@@ -3179,9 +4247,10 @@ export const HC_SOURCES = new Map([
|
|
|
3179
4247
|
"; [RotorRouter [2, [], []], RotorRouter [1, [5], []], RotorRouter [2, [5]], RotorRouter [1, []]]",
|
|
3180
4248
|
"# [$!!.invalid-router, $!!.invalid-router, $!!.invalid-router, $!!.invalid-router]",
|
|
3181
4249
|
"```",
|
|
3182
|
-
"Anything but
|
|
4250
|
+
"Anything but a nonempty list of arrays is refused. One channel or three are",
|
|
4251
|
+
"not refused: they are routers of another arity (007.27, `hc/division.hc`)",
|
|
3183
4252
|
"```",
|
|
3184
|
-
"; [RotorRouter [[], 5], RotorRouter [(1, 2), []], RotorRouter [
|
|
4253
|
+
"; [RotorRouter [[], 5], RotorRouter [(1, 2), []], RotorRouter [], RotorRouter [[], [5], []], RotorRouter 5, RotorRouter ()]",
|
|
3185
4254
|
"# [$!!.invalid-router, $!!.invalid-router, $!!.invalid-router, $!!.invalid-router, $!!.invalid-router, $!!.invalid-router]",
|
|
3186
4255
|
"```",
|
|
3187
4256
|
"A channel is its elements. The router keeps them in an array of its own, so a",
|
|
@@ -3484,8 +4553,8 @@ export const HC_SOURCES = new Map([
|
|
|
3484
4553
|
"printed form is matched here by its beginning",
|
|
3485
4554
|
"```",
|
|
3486
4555
|
"; RotorRouter [[5], []]",
|
|
3487
|
-
"# [.phase 1; .left [5]; .right []; .apply_ {...",
|
|
3488
|
-
"; (RotorRouter [[5], []]) = [.phase 1; .left [5]; .right []; .apply_ { .x _; .l (_^ .left); .r (_^ .right); .n (l.# + r.#); ((n %% 2) = 0) ? {
|
|
4556
|
+
"# [.phase 1; .left [5]; .right []; .channels [[5], []]; .apply_ {...",
|
|
4557
|
+
"; (RotorRouter [[5], []]) = [.phase 1; .left [5]; .right []; .channels [[5], []]; .apply_ { .x _; .l (_^ .left); .r (_^ .right); .n (l.# + r.#); ((n %% 2) = 0) ? { .nl (l x); @left nl; @channels [nl, r]; @phase 1; } : { .nr (r x); @right nr; @channels [l, nr]; @phase 2; }; }; .# { .l (_^ .left); .r (_^ .right); l.# + r.# }; .## { (channel-load (_^ .left)) + (channel-load (_^ .right)) }; .### { (channel-load (_^ .left)) - (channel-load (_^ .right)) }; ./ { .ways _; ((_^^ .history) (_^ .channels)) / ways }; .toText { “RotorRouter(” (_^ .left) “,” (_^ .right) “)” };]",
|
|
3489
4558
|
"# <>",
|
|
3490
4559
|
"```",
|
|
3491
4560
|
"## Importing",
|