hclang 0.41.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1104,6 +1104,63 @@ export const HC_SOURCES = new Map([
|
|
|
1104
1104
|
"; [Outer.ks(), Inner.ks()]",
|
|
1105
1105
|
"# [[1, 1], [5, 5]]",
|
|
1106
1106
|
"",
|
|
1107
|
+
"`A class answers a binary arithmetic operator on its instances by declaring a",
|
|
1108
|
+
"method under the operator's own name, + - * or /, the way it declares apply or",
|
|
1109
|
+
"toText (015.02). The operator resolves against its left operand's declared",
|
|
1110
|
+
"method and the global built-in, and never the lexical scope the operand was",
|
|
1111
|
+
"read from. A declared method takes the right operand and answers the result.`",
|
|
1112
|
+
"; .Vec [.n 3; .+ {.a (_^ .n); .b (_ .n); [.n (a + b)]}];",
|
|
1113
|
+
"; (Vec + [.n 4]).n",
|
|
1114
|
+
"# 7",
|
|
1115
|
+
"",
|
|
1116
|
+
"`The declared operator overrides the global built-in only when the aggregate is",
|
|
1117
|
+
"the left operand. Ordinary numeric arithmetic keeps the global operation.`",
|
|
1118
|
+
"; 2 + 3",
|
|
1119
|
+
"# 5",
|
|
1120
|
+
"",
|
|
1121
|
+
"`A declared operator resolves through the declared-parent chain, the same chain",
|
|
1122
|
+
"an aggregate's other methods come from, so a child inherits it.`",
|
|
1123
|
+
"; .AddBase [.n 0; .+ {.a (_^ .n); .b (_ .n); [.n (a + b)]}];",
|
|
1124
|
+
"; .AddKid [.^ AddBase; .n 10];",
|
|
1125
|
+
"; (AddKid + [.n 5]).n",
|
|
1126
|
+
"# 15",
|
|
1127
|
+
"",
|
|
1128
|
+
"`A lexical operator-named method in the surrounding scope does not shadow global",
|
|
1129
|
+
"arithmetic for an ordinary numeric left operand, which carries no lexical scope",
|
|
1130
|
+
"into the operator.`",
|
|
1131
|
+
"; .+ {999};",
|
|
1132
|
+
"; 2 + 3",
|
|
1133
|
+
"# 5",
|
|
1134
|
+
"",
|
|
1135
|
+
"`Nor does a receiver's own declared + shadow the global + used inside that",
|
|
1136
|
+
"receiver's other methods. A numeric load read back from the receiver and used",
|
|
1137
|
+
"with + takes the global operation, so there is no receiver-scope recursion or",
|
|
1138
|
+
"stack overflow. A lexical walk would find the class's own + and recur; before",
|
|
1139
|
+
"015.02 this spelling overflowed the stack.`",
|
|
1140
|
+
"; .Ring [.base 2; .+ {_ + 100}; .inc {(_^ .base) + 3}];",
|
|
1141
|
+
"; Ring.inc()",
|
|
1142
|
+
"# 5",
|
|
1143
|
+
"",
|
|
1144
|
+
"`The same receiver still answers + when it is itself the left operand, resolving",
|
|
1145
|
+
"its own declared method rather than the global built-in.`",
|
|
1146
|
+
"; Ring + 100",
|
|
1147
|
+
"# 200",
|
|
1148
|
+
"",
|
|
1149
|
+
"`The declared-operator hook is scoped to the arithmetic spellings + - * / only.",
|
|
1150
|
+
"A built-in operator outside that set, such as membership ~, is unaffected: a",
|
|
1151
|
+
"class that declares .~ does not intercept it, and the global operation answers",
|
|
1152
|
+
"for an aggregate and for a number alike.`",
|
|
1153
|
+
"; .Thing [.~ {999}; .v 5];",
|
|
1154
|
+
"; Thing ~ ([].<>)",
|
|
1155
|
+
"# <>",
|
|
1156
|
+
"; 5 ~ (0.<>)",
|
|
1157
|
+
"# <>",
|
|
1158
|
+
"",
|
|
1159
|
+
"`A named arithmetic spelling, 2 .+ 2, is ordinary application and not the binary",
|
|
1160
|
+
"operator, so it is unchanged.`",
|
|
1161
|
+
"; 2 .+ 2",
|
|
1162
|
+
"# 4",
|
|
1163
|
+
"",
|
|
1107
1164
|
].join("\n"),
|
|
1108
1165
|
],
|
|
1109
1166
|
[
|
|
@@ -1430,9 +1487,81 @@ export const HC_SOURCES = new Map([
|
|
|
1430
1487
|
"",
|
|
1431
1488
|
"**Scaling**, `d.scale_ k`: multiply both loads by a Count k, keeping the",
|
|
1432
1489
|
"phase. It is the numerical shadow of Star: `(x * y).####` is",
|
|
1433
|
-
"`x.####.scale_ (y.##)` for a nonempty host x.
|
|
1434
|
-
"
|
|
1435
|
-
"
|
|
1490
|
+
"`x.####.scale_ (y.##)` for a nonempty host x. `scale_` stays, as the name the",
|
|
1491
|
+
"fourth hash and Star correspondence use; `d * k` now answers the same Demi",
|
|
1492
|
+
"through the operator below.",
|
|
1493
|
+
"",
|
|
1494
|
+
"**Arithmetic**, `d + x`, `d - x` and `d * x` (015.11). A class answers an",
|
|
1495
|
+
"operator by declaring a method under its name, found on the operand and its",
|
|
1496
|
+
"declared parents, the chain its other methods come from, so an operator in a",
|
|
1497
|
+
"method body keeps its global meaning rather than recurring into the class that",
|
|
1498
|
+
"is running. All three **construct a fresh Demi state** from the one Size",
|
|
1499
|
+
"observation `x.##` of their operand, keeping Figure 008's distinction between",
|
|
1500
|
+
"construction and observation. They are **fixed-channel load transformations**",
|
|
1501
|
+
"on the two-load shadow, consistent with what a `RotorRouter`",
|
|
1502
|
+
"(`hc/rotor-router.hc`) does to its channel loads: `+` and `-` add `x.##` to one",
|
|
1503
|
+
"fixed channel's load the way a route adds a Frame's Size to the channel it lands",
|
|
1504
|
+
"in, and `*` is the Star shadow `scale_`. These are correspondences, not a claim",
|
|
1505
|
+
"that the Router declares named `+`, `-` or `*` methods: the Router declares only",
|
|
1506
|
+
"`apply_` (alternating route-and-flip), `.#`, `.##` and `.###` (its phase, total",
|
|
1507
|
+
"load and signed residual). None of the three Demi operators is application: none",
|
|
1508
|
+
"flips the phase, and each answers a fresh value and leaves `d` as it was.",
|
|
1509
|
+
"",
|
|
1510
|
+
"- `d + x` is the **tally** operator: it deposits `x.##` on the **right**,",
|
|
1511
|
+
" `Demi [p, L, R + x.##]`. This is the transformation a route into the router's",
|
|
1512
|
+
" right channel induces on the loads — that channel's load grows by the routed",
|
|
1513
|
+
" Frame's Size — but it targets a fixed channel without flipping the phase,",
|
|
1514
|
+
" rather than invoking the Router's alternating `apply_`. A sizeless host's",
|
|
1515
|
+
" failure is the answer, as it is for application.",
|
|
1516
|
+
"- `d - x` is the **alternator** operator: it deposits on the **left**,",
|
|
1517
|
+
" `Demi [p, L + x.##, R]`, the load transformation a route into the left channel",
|
|
1518
|
+
" induces. It is not subtraction: a deposit only ever adds, so a load never goes",
|
|
1519
|
+
" negative and stays a whole Count. Right deposition lowers the signed residual",
|
|
1520
|
+
" `L − R` and left deposition raises it, the reverse of ordinary signed-scalar",
|
|
1521
|
+
" `+` and `-`.",
|
|
1522
|
+
"- `d * x` is the **inlay** operator: it scales both loads by the operand's Size",
|
|
1523
|
+
" `x.##`, `Demi [p, sL, sR]` for `s = x.##`, keeping the phase. It reads the",
|
|
1524
|
+
" operand through the one Size observer, as `+` and `-` do, so any sized Frame",
|
|
1525
|
+
" scales a Demi, not only a bare Count. A sizeless host's failure is the answer,",
|
|
1526
|
+
" as it is for application. Because `x.##` is always a nonnegative whole Count",
|
|
1527
|
+
" when present, the loads stay whole Counts and the result is a valid Demi. It",
|
|
1528
|
+
" is literally `d.scale_ (x.##)`: `*` reads the Size, then hands it to `scale_`,",
|
|
1529
|
+
" which is the Star shadow (`(x * y).####` is `x.####.scale_ (y.##)` for a",
|
|
1530
|
+
" nonempty host x) and already takes a Size. Delegating to `scale_` builds the",
|
|
1531
|
+
" fresh Demi by a load-only functional update, never naming the `Demi`",
|
|
1532
|
+
" constructor inside the method, so a unit-taggable operand such as a decimal",
|
|
1533
|
+
" cannot shadow the constructor through the argument scope; `D * 2.5` scales by",
|
|
1534
|
+
" `(2.5).## = 2`.",
|
|
1535
|
+
"",
|
|
1536
|
+
"None of these is sequential application: `d x` deposits in the active channel",
|
|
1537
|
+
"and flips the phase, while `+`, `-` and `*` choose a channel explicitly and",
|
|
1538
|
+
"keep it. So `+` and `-` reach states a run cannot, a phase-2 Demi with a load",
|
|
1539
|
+
"on the odd side, and `*` is the Star shadow, not a repeated deposit.",
|
|
1540
|
+
"",
|
|
1541
|
+
"**No division (015.11).** A Demi declares **no** `/` operator. Division is not a",
|
|
1542
|
+
"Router construction: the router constructs tally, alternator and inlay — Count,",
|
|
1543
|
+
"residual and Size — and nothing in that native structure earns a quotient. The",
|
|
1544
|
+
"earlier signed-ratio `d / x` (015.02) and the Size-uniform `d / x` (015.09a)",
|
|
1545
|
+
"are both removed. There is no modular Spin, renamed quotient, `phase`, or other",
|
|
1546
|
+
"division surrogate in their place. A `D / x` now falls back to the global `/`",
|
|
1547
|
+
"operator (`lib/ops/math.ts`), which has no numeric meaning for a non-numeric",
|
|
1548
|
+
"Demi left operand and **answers nil**; it does **not** silently preserve a Demi",
|
|
1549
|
+
"signed quotient through another path. An operand that is already an error still",
|
|
1550
|
+
"propagates, left operand first, as it does for `+`, `-` and `*`. This removes",
|
|
1551
|
+
"only the Demi-specific operator: the global language `/` and `hc/figures.hc`'s",
|
|
1552
|
+
"`spin` observation (signed residual over a positive Count, on any host) are",
|
|
1553
|
+
"untouched.",
|
|
1554
|
+
"",
|
|
1555
|
+
"**Compatibility (015.11).** The three constructive operators `+`, `-` and `*`",
|
|
1556
|
+
"read their operand through the one Size observer `x.##`; `+` and `-` are",
|
|
1557
|
+
"unchanged from 015.02, and `*` keeps its 015.09a Size-uniform domain. `D * 3` is",
|
|
1558
|
+
"unchanged, because `3.## = 3`; a non-Count sized operand such as another Demi,",
|
|
1559
|
+
"an aggregate, or a decimal scales by its Size (`D * 2.5` scales by `2`, since",
|
|
1560
|
+
"`(2.5).## = 2`); and a sizeless operand propagates its own failure. `scale_` is",
|
|
1561
|
+
"unchanged and still takes a Count directly; `*` equals `d.scale_ (x.##)` for",
|
|
1562
|
+
"every sized `x`. The only removal is the Demi `/` operator: a call that",
|
|
1563
|
+
"previously answered a signed Spin, such as `D / 2`, is no longer a Demi",
|
|
1564
|
+
"operation.",
|
|
1436
1565
|
"",
|
|
1437
1566
|
"**Text.** A Demi prints as what it is, an aggregate of fields and methods, and",
|
|
1438
1567
|
"that reads back as the same Demi. As text it reads `Demi(<>,12,3)`, with the",
|
|
@@ -1457,6 +1586,12 @@ export const HC_SOURCES = new Map([
|
|
|
1457
1586
|
" (s ~ (0.<>)) ? {((_^^ .phase) = 2) ? {@left (l + s); @phase 1;} : {@right (r + s); @phase 2;}; _^^} : {s}};",
|
|
1458
1587
|
" .scale_ {.k _; .l (_^ .left); .r (_^ .right);",
|
|
1459
1588
|
" (k ~ (0.<>)) ? {@left (l * k); @right (r * k); _^^} : {$!!.invalid-scale}};",
|
|
1589
|
+
" .+ {.s (_ .##); .p (_^ .phase); .l (_^ .left); .r (_^ .right);",
|
|
1590
|
+
" (s ~ (0.<>)) ? {Demi [p, l, (r + s)]} : {s}};",
|
|
1591
|
+
" .- {.s (_ .##); .p (_^ .phase); .l (_^ .left); .r (_^ .right);",
|
|
1592
|
+
" (s ~ (0.<>)) ? {Demi [p, (l + s), r]} : {s}};",
|
|
1593
|
+
" .* {.s (_ .##);",
|
|
1594
|
+
" (s ~ (0.<>)) ? {(_^^ .scale_ s)} : {s}};",
|
|
1460
1595
|
" .toText {“Demi(” (((_^ .phase) = 2) ? {“<>”} : {“()”}) “,” (_^ .left) “,” (_^ .right) “)”}",
|
|
1461
1596
|
" ]} : {$!!.invalid-demi}} : {$!!.invalid-demi}};",
|
|
1462
1597
|
"```",
|
|
@@ -1615,11 +1750,104 @@ export const HC_SOURCES = new Map([
|
|
|
1615
1750
|
"; [([5, 3] * 3).#### = ([5, 3].####.scale_ 3), ([[[]], []] * [[], []]).#### = ([[[]], []].####.scale_ ([[], []].##))]",
|
|
1616
1751
|
"# [<>, <>]",
|
|
1617
1752
|
"```",
|
|
1618
|
-
"
|
|
1619
|
-
"
|
|
1753
|
+
"## Arithmetic",
|
|
1754
|
+
"",
|
|
1755
|
+
"Three operators act on a Demi's state, each reading its operand through the one",
|
|
1756
|
+
"Size observer `x.##`. They are fixed-channel load transformations consistent",
|
|
1757
|
+
"with a `RotorRouter`'s channel loads (`hc/rotor-router.hc`), not named Router",
|
|
1758
|
+
"methods: the Router declares only `apply_`, `.#`, `.##` and `.###`. `+`, `-`",
|
|
1759
|
+
"and `*` **construct a fresh Demi** from observations of their operands: `+` is",
|
|
1760
|
+
"tally, depositing `x.##` on the right; `-` is alternator, depositing on the",
|
|
1761
|
+
"left; and `*` is inlay, scaling both loads by `x.##` through `scale_`, the Star",
|
|
1762
|
+
"shadow. Each keeps the phase, answers a fresh value and leaves its operand as it",
|
|
1763
|
+
"was, so they compose by nesting. There is **no** `/`: a Demi declares no",
|
|
1764
|
+
"division operator",
|
|
1765
|
+
"```",
|
|
1766
|
+
"; .D (Demi [2, 5, 3]);",
|
|
1767
|
+
"; [“” (D + 4), “” (D - 4), “” (D * 3)]",
|
|
1768
|
+
"# [“Demi(<>,5,7)”, “Demi(<>,9,3)”, “Demi(<>,15,9)”]",
|
|
1769
|
+
"; [“” ((D + 4) - 2), “” ((D - 2) + 4), “” ((D + 4) * 3)]",
|
|
1770
|
+
"# [“Demi(<>,7,7)”, “Demi(<>,7,7)”, “Demi(<>,15,21)”]",
|
|
1771
|
+
"; “” D",
|
|
1772
|
+
"# “Demi(<>,5,3)”",
|
|
1773
|
+
"```",
|
|
1774
|
+
"A deposit keeps the phase, including phase 1, where application would flip it,",
|
|
1775
|
+
"and a zero Size deposits nothing while still answering a Demi. The operand is",
|
|
1776
|
+
"measured by its Size, so any sized Frame deposits",
|
|
1777
|
+
"```",
|
|
1778
|
+
"; [(D + 4).#, (D - 4).#, (D * 3).#]",
|
|
1779
|
+
"# [2, 2, 2]",
|
|
1780
|
+
"; .P (Demi [1, 5, 3]);",
|
|
1781
|
+
"; [“” (P + 4), (P + 4).#, “” (P - 4)]",
|
|
1782
|
+
"# [“Demi((),5,7)”, 1, “Demi((),9,3)”]",
|
|
1783
|
+
"; [“” (D + 0), “” (D - 0), “” (D [3, 4])]",
|
|
1784
|
+
"# [“Demi(<>,5,3)”, “Demi(<>,5,3)”, “Demi((),12,3)”]",
|
|
1785
|
+
"```",
|
|
1786
|
+
"Deposit is not application and deposit is not subtraction. `D x` flips the",
|
|
1787
|
+
"phase and `D + x` does not, so they reach different states; `D - x` adds to the",
|
|
1788
|
+
"left load and never takes from the right, so a load stays a whole Count and the",
|
|
1789
|
+
"signed residual only rises",
|
|
1790
|
+
"```",
|
|
1791
|
+
"; [(D + 4).###, (D - 4).###, D.###]",
|
|
1792
|
+
"# [-2, 6, 2]",
|
|
1793
|
+
"; [((D 4).# = (D + 4).#), (D 4).###, (D + 4).###]",
|
|
1794
|
+
"# [(), 6, -2]",
|
|
1795
|
+
"```",
|
|
1796
|
+
"Order of a right then a left deposit does not matter, and scaling after a",
|
|
1797
|
+
"balanced deposit is the Star shadow of scaling first",
|
|
1798
|
+
"```",
|
|
1799
|
+
"; [((D + 4) - 2) = ((D - 2) + 4), ((D + 4) * 3) = ((D * 3) + 12)]",
|
|
1800
|
+
"# [<>, <>]",
|
|
1801
|
+
"```",
|
|
1802
|
+
"A sizeless host refuses on all three operators, its failure the answer, as",
|
|
1803
|
+
"application refuses it. `*` reads its operand's Size rather than demanding a",
|
|
1804
|
+
"bare Count, so a Demi, an aggregate or a decimal works through its `.##`, while",
|
|
1805
|
+
"`D * 0` still annihilates",
|
|
1806
|
+
"```",
|
|
1807
|
+
"; [D + ([].nope), D - ([].nope), D * ([].nope)]",
|
|
1808
|
+
"# [$!.name-missing “..., $!.name-missing “..., $!.name-missing “...]",
|
|
1809
|
+
"```",
|
|
1810
|
+
"`*` scales by the operand's Size, so its domain is every sized Frame: a Demi",
|
|
1811
|
+
"contributes `L + R`, an aggregate its element count, a decimal its truncated",
|
|
1812
|
+
"magnitude, and a zero Size annihilates both loads. `D * 3` is unchanged, since",
|
|
1813
|
+
"`3.## = 3`, and the result keeps the phase in either parity",
|
|
1814
|
+
"```",
|
|
1815
|
+
"; [“” (D * (Demi [1, 2, 4])), “” (D * [[], []]), “” (D * 2.5), “” (D * 0)]",
|
|
1816
|
+
"# [“Demi(<>,30,18)”, “Demi(<>,10,6)”, “Demi(<>,10,6)”, “Demi(<>,0,0)”]",
|
|
1817
|
+
"; [“” (D * 1), (D * 3).#, (P * 3).#, “” (P * 3)]",
|
|
1818
|
+
"# [“Demi(<>,5,3)”, 2, 1, “Demi((),15,9)”]",
|
|
1819
|
+
"```",
|
|
1820
|
+
"The signed-scalar reading misleads: `+` lowers the residual and `-` raises it,",
|
|
1821
|
+
"so `D + 4` is not “larger” than `D`, and `D - 4` is not `D` made smaller",
|
|
1822
|
+
"```",
|
|
1823
|
+
"; [(D + 4).### .< D.###, (D - 4).### .> D.###]",
|
|
1824
|
+
"# [<>, <>]",
|
|
1825
|
+
"```",
|
|
1826
|
+
"## No Demi division (015.11)",
|
|
1827
|
+
"",
|
|
1828
|
+
"A Demi declares **no** `/` operator: division is not a Router construction. A",
|
|
1829
|
+
"`D / x` is not a Demi operation at all; dispatch falls through to the global",
|
|
1830
|
+
"`/`, which has no numeric meaning for a non-numeric left operand and answers",
|
|
1831
|
+
"nil, never a signed quotient. A zero or a Demi divisor is nil the same way, so",
|
|
1832
|
+
"there is no hidden division-by-zero path and no Demi-as-Spin through another",
|
|
1833
|
+
"name. Only a failing operand changes the answer, because the global `/`",
|
|
1834
|
+
"propagates an operand that is already an error, exactly as `+`, `-` and `*` do",
|
|
1835
|
+
"```",
|
|
1836
|
+
"; .Dp (Demi [2, 3, 5]); .E (Demi [1, 2, 4]);",
|
|
1837
|
+
"; [D / 2, D / 4, Dp / 2, D / E]",
|
|
1838
|
+
"# [(), (), (), ()]",
|
|
1839
|
+
"; [D / 0, (Demi [2, 4, 4]) / 0, D / (0 - 4), D / 2.5]",
|
|
1840
|
+
"# [(), (), (), ()]",
|
|
1841
|
+
"; D / ([].nope)",
|
|
1842
|
+
"# $!.name-missing “...",
|
|
1843
|
+
"```",
|
|
1844
|
+
"The global language `/` and the `spin` observation in `hc/figures.hc` are",
|
|
1845
|
+
"untouched: `spin` still answers the signed residual over a positive Count on",
|
|
1846
|
+
"any host, and a plain numeric `/` still divides. Removing the Demi operator",
|
|
1847
|
+
"removes only the Demi-specific division",
|
|
1620
1848
|
"```",
|
|
1621
|
-
"; [
|
|
1622
|
-
"# [
|
|
1849
|
+
"; [“” (6 / 2), (D.### / 2) = 1]",
|
|
1850
|
+
"# [“3”, <>]",
|
|
1623
1851
|
"```",
|
|
1624
1852
|
"## A precise regression: a load read at the wrong depth",
|
|
1625
1853
|
"",
|
|
@@ -249,6 +249,25 @@ export class FrameArray extends FrameList {
|
|
|
249
249
|
}
|
|
250
250
|
return undefined;
|
|
251
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* The method this aggregate declares for the operator `key`, bound to it as
|
|
254
|
+
* the left operand, or undefined when it declares none (015.02).
|
|
255
|
+
*
|
|
256
|
+
* Found on the aggregate or its declared parents, the same class chain its
|
|
257
|
+
* other methods come from, and never in the scope around it, so an operator
|
|
258
|
+
* written inside a method body keeps its ordinary meaning rather than
|
|
259
|
+
* recurring into the class that is running. The method runs immutably, like a
|
|
260
|
+
* declared observation: a deposit answers a fresh instance, as a functional
|
|
261
|
+
* update does, and leaves the left operand unchanged.
|
|
262
|
+
*/
|
|
263
|
+
declaredOperator(key) {
|
|
264
|
+
if (!FrameArray.OPERATOR_KEYS.includes(key))
|
|
265
|
+
return undefined;
|
|
266
|
+
const method = this.declaredMethod(key);
|
|
267
|
+
if (!method)
|
|
268
|
+
return undefined;
|
|
269
|
+
return new BoundMethod(method, this, false, methodEffect(key));
|
|
270
|
+
}
|
|
252
271
|
/**
|
|
253
272
|
* What this aggregate contributes when text receives it (#398).
|
|
254
273
|
*
|
|
@@ -455,6 +474,26 @@ Object.defineProperty(FrameArray, "APPLICATION_KEYS", {
|
|
|
455
474
|
writable: true,
|
|
456
475
|
value: ["apply_", "apply"]
|
|
457
476
|
});
|
|
477
|
+
/**
|
|
478
|
+
* The operators an aggregate may declare its own answer to (015.02).
|
|
479
|
+
*
|
|
480
|
+
* These are the ordinary binary arithmetic spellings. A class declares one
|
|
481
|
+
* as a method under the operator's own name, `+`, `-`, `*` or `/`, the way
|
|
482
|
+
* it declares `apply`, `#` or `toText`. The method takes the right operand
|
|
483
|
+
* and answers the operation's result, so the class decides what the operator
|
|
484
|
+
* means on its instances without any special case in the evaluator.
|
|
485
|
+
*/
|
|
486
|
+
Object.defineProperty(FrameArray, "OPERATOR_KEYS", {
|
|
487
|
+
enumerable: true,
|
|
488
|
+
configurable: true,
|
|
489
|
+
writable: true,
|
|
490
|
+
value: [
|
|
491
|
+
"+",
|
|
492
|
+
"-",
|
|
493
|
+
"*",
|
|
494
|
+
"/",
|
|
495
|
+
]
|
|
496
|
+
});
|
|
458
497
|
/** The key an aggregate declares its readable text under (#398). */
|
|
459
498
|
Object.defineProperty(FrameArray, "TEXT_KEY", {
|
|
460
499
|
enumerable: true,
|
|
@@ -448,7 +448,27 @@ export class FrameOperator extends FrameSymbol {
|
|
|
448
448
|
return bound;
|
|
449
449
|
}
|
|
450
450
|
called_by(context) {
|
|
451
|
-
|
|
451
|
+
// An operator resolves against its left operand and the global table only,
|
|
452
|
+
// never the lexical scope the operand was read from (015.02). A class may
|
|
453
|
+
// answer an operator on its own instances by declaring a method under the
|
|
454
|
+
// operator's name, found on the operand and its declared parents, the chain
|
|
455
|
+
// its other methods come from. Resolving nothing else keeps an operator
|
|
456
|
+
// written inside a method body meaning the global operation rather than
|
|
457
|
+
// recurring into the class that is running, which a lexical walk would do
|
|
458
|
+
// for a load read back from the receiver.
|
|
459
|
+
const left = context.referent();
|
|
460
|
+
if (left instanceof FrameArray) {
|
|
461
|
+
const declared = left.declaredOperator(this.data);
|
|
462
|
+
if (declared)
|
|
463
|
+
return declared;
|
|
464
|
+
}
|
|
465
|
+
const globals = Frame.globals;
|
|
466
|
+
const resolved = typeof globals.operation === "function"
|
|
467
|
+
? globals.operation(this.data, context)
|
|
468
|
+
: Frame.missing;
|
|
469
|
+
const value = resolved.is.missing
|
|
470
|
+
? FrameSymbol.for(this.data).called_by(context)
|
|
471
|
+
: resolved;
|
|
452
472
|
return value instanceof FrameCurry && this.receiverState
|
|
453
473
|
? value.withReceiverState(this.receiverState)
|
|
454
474
|
: value;
|
package/esm/lib/ops/frame-ops.js
CHANGED
|
@@ -17,6 +17,19 @@ export class FrameOps extends Frame {
|
|
|
17
17
|
}
|
|
18
18
|
return Frame.missing;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* The built-in operation for `key`, curried to `origin` as its left operand,
|
|
22
|
+
* or missing when there is no such operation (015.02).
|
|
23
|
+
*
|
|
24
|
+
* Operator dispatch resolves a left operand's own declared method first, then
|
|
25
|
+
* this global table, and never the lexical scope the operand was read from.
|
|
26
|
+
* That keeps an operator written inside a method body meaning the global
|
|
27
|
+
* operation rather than the class's own method for the same spelling.
|
|
28
|
+
*/
|
|
29
|
+
operation(key, origin) {
|
|
30
|
+
const func = this.OpsDict[key];
|
|
31
|
+
return func != null ? this.curry(func, origin, key) : Frame.missing;
|
|
32
|
+
}
|
|
20
33
|
toString() {
|
|
21
34
|
return this.OpsDict.toString();
|
|
22
35
|
}
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.42.0";
|