hclang 0.21.1 → 0.22.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.
@@ -406,6 +406,8 @@ export const HC_SOURCES = new Map([
406
406
  "# 6",
407
407
  "; 2 “a”",
408
408
  "# “aa”",
409
+ "; 2 [1, 2]",
410
+ "# [1, 2, 1, 2]",
409
411
  "; [] 1",
410
412
  "# [1]",
411
413
  "; [1] 2",
@@ -559,6 +561,16 @@ export const HC_SOURCES = new Map([
559
561
  "; [1] 2",
560
562
  "# [1, 2]",
561
563
  "```",
564
+ "Integer repetition consults the same declaration. A count concatenates a plain",
565
+ "aggregate's elements, even where the scope binds `apply`, but repeats an",
566
+ "aggregate that declares `apply` by its rule: the first of the n steps answers",
567
+ "the receiver, and each later step applies the running answer to it, so here the",
568
+ "rule runs four times",
569
+ "```",
570
+ "; .Units {[.row _; .apply {Units (_^.row + 1)}]};",
571
+ "; [(5 (Units 0)).row, (5 [Units 0]).#]",
572
+ "# [4, 5]",
573
+ "```",
562
574
  "",
563
575
  "## An empty reduce answers its receiver; an empty map is empty",
564
576
  "",
@@ -1069,8 +1081,26 @@ export const HC_SOURCES = new Map([
1069
1081
  "never affects `=`. Every observer answers a Figure, never a number or a",
1070
1082
  "Boolean: `A`, with no children, means no, and `B` means yes. So every answer can",
1071
1083
  "be a child, a receiver, or an argument, and the class is closed under its own",
1072
- "methods. Only Form and Text leave the class, on purpose: they answer a plain",
1073
- "bracket tree and its text, for reading a Figure rather than computing with it.",
1084
+ "methods. Only Cells, Form and Text leave the class, on purpose: Cells and Form",
1085
+ "answer a plain bracket tree and Text spells one, for reading a Figure rather",
1086
+ "than computing with it. A tally also reads as a natural number. Its children",
1087
+ "are an aggregate, so `(x.size()).children.#` is the FrameCount it spells and",
1088
+ "`x.children.#` counts x's children. A Figure's own `.#` and `.##` are `0`,",
1089
+ "because its children are a property rather than its elements (#407, #411).",
1090
+ "",
1091
+ "Size, Multiplication and Tally multiplication count first and then construct.",
1092
+ "Each computes a count n natively, with Cells and the size operators, and builds",
1093
+ "`Figure (n [U])` or `Figure (n [y])`, with the guards for zero that their",
1094
+ "paragraphs give. Repeating an aggregate concatenates its elements and shares",
1095
+ "them, so `n [U]` is n units, each `U` itself. Before v0.22.0 Size joined its",
1096
+ "children's Sizes one unit at a time, so tallies added by joining. Tallies still",
1097
+ "are the natural numbers in unary, they still join, `ys | x`, and two of them",
1098
+ "add as the Size of a Figure holding both, `(Figure [x, y]).size()`. Size now",
1099
+ "trades the joining derivation for construction from a native count.",
1100
+ "Repetition holds at most 1,000,000 elements, so Size, Multiplication and Tally",
1101
+ "multiplication answer `$!.repetition-size 1000000` once their count passes",
1102
+ "that. The joining Size had no such ceiling, but its time grew quadratically",
1103
+ "with the cells.",
1074
1104
  "",
1075
1105
  "A method names its own Figure `_^`, because a bare name is looked up on the",
1076
1106
  "argument first (spec 7), and the argument is usually another Figure. For the",
@@ -1096,29 +1126,43 @@ export const HC_SOURCES = new Map([
1096
1126
  " .many {Figure (_^.children & {B})};",
1097
1127
  "```",
1098
1128
  "**Size**, `x.size()`: a tally with one unit cell `U` per cell. Any Figure shaped",
1099
- "like `U` is a cell; every other Figure adds up the Sizes of its children by",
1100
- "joining them into `Tally Z`. It keeps the cell count and forgets shape, nesting,",
1101
- "order, reuse and identity. The unit case comes first, because a unit's only",
1102
- "child is `Z`",
1129
+ "like `U` is a cell. Size counts them with Cells, below, and repeats `U` that",
1130
+ "many times, and a Figure with no cells answers `Z` itself. It keeps the cell",
1131
+ "count and forgets shape, nesting, order, reuse and identity",
1132
+ "```;",
1133
+ " .size {.n ((_^.cells()).##); (n = 0) ? {Z} : {Figure (n [U])}};",
1134
+ "```",
1135
+ "**Cells**, `x.cells()`: the bracket tree of x with `1` in place of each cell,",
1136
+ "so `(x.cells()).##` is the Size of x as a natural number, counted without",
1137
+ "joining a tally. A count is its own size, so the `1` of a unit is already its",
1138
+ "count. It keeps the cell count and where the cells are, and forgets identity.",
1139
+ "The unit case comes first, because a unit's only child is `Z`",
1103
1140
  "```;",
1104
- " .size {.kids _^.children;",
1105
- " (kids = U.children) ? {Figure [U]} : {((kids & {_.size()}) | (Tally Z)).row}};",
1141
+ " .cells {.kids _^.children;",
1142
+ " (kids = U.children) ? {1} : {kids & {_.cells()}}};",
1106
1143
  "```",
1107
- "**Multiplication**, `x.mul y`: y once for every cell of x, and `Z` when y is",
1108
- "`Z`. It keeps y's identity in every position and forgets x's shape",
1144
+ "**Multiplication**, `x.mul y`: y once for every cell of x, counted as Size",
1145
+ "counts them, and `Z` when y is `Z`. Repetition shares what it repeats, so it",
1146
+ "keeps y's identity in every position, and it forgets x's shape",
1109
1147
  "```;",
1110
- " .mul {.y _; .cells ((_^.size()).children);",
1111
- " (y = Z) ? {Z} : {Figure (cells & {y})}};",
1148
+ " .mul {.y _; .n ((_^.cells()).##); (y = Z) ? {Z} : {Figure (n [y])}};",
1112
1149
  "```",
1113
1150
  "**Tally multiplication**, `x.size_mul y`: the Size of a Figure holding y once",
1114
- "per child of x. It keeps the cell count and forgets both shapes",
1151
+ "per child of x. That is x's number of children times y's cells, so it is",
1152
+ "counted rather than built, and it is `Z` when the product is `0`, a y of `Z`",
1153
+ "included. Building the Figure would go wrong there, as Multiplication would",
1154
+ "without its guard: one row of nothing, `Figure [Z]`, has the form of `U` and",
1155
+ "would count as a cell. It keeps the cell count and forgets both shapes",
1115
1156
  "```;",
1116
- " .size_mul {.y _; (Figure (_^.children & {y})).size()};",
1157
+ " .size_mul {.n ((_^.children.#) * ((_.cells()).##));",
1158
+ " (n = 0) ? {Z} : {Figure (n [U])}};",
1117
1159
  "```",
1118
1160
  "**Size-equivalence**, `x.size_equivalent y`: `U` when the two Sizes agree and",
1119
- "`Z` otherwise. It keeps only whether the cell counts agree",
1161
+ "`Z` otherwise. It compares the two cell counts as natural numbers, which",
1162
+ "agree exactly when the two tallies do, so it joins no tally. It keeps only",
1163
+ "whether the cell counts agree",
1120
1164
  "```;",
1121
- " .size_equivalent {((_^.size()) = (_.size())) ? {U} : {Z}};",
1165
+ " .size_equivalent {(((_^.cells()).##) = ((_.cells()).##)) ? {U} : {Z}};",
1122
1166
  "```",
1123
1167
  "**Sameness of form**, `x.sameform y`: `B` when `x = y`. It compares child by",
1124
1168
  "child and forgets identity and reuse",
@@ -1154,12 +1198,6 @@ export const HC_SOURCES = new Map([
1154
1198
  " .toText {“” (_^.form())}",
1155
1199
  "]};",
1156
1200
  "```",
1157
- "**Tally** is a helper receiver, not a Figure. Its `row` starts at `Z`, and",
1158
- "applying a tally to it appends that tally's units, one at a time, through",
1159
- "`x y`, so a reduce into `Tally Z` adds counts",
1160
- "```",
1161
- ".Tally {[.row _; .apply {Tally (_.children | _^.row)}]};",
1162
- "```",
1163
1201
  "**The marks.** The observers answer `A`, the Figure with no children, for no",
1164
1202
  "and `B`, the Figure holding `A`, for yes. Size counts in the same two: `Z`",
1165
1203
  "reuses `A` as the additive zero and `U` reuses `B` as the unit cell. The class",
@@ -1199,6 +1237,13 @@ export const HC_SOURCES = new Map([
1199
1237
  "; ([A, B] & (Figure [C])) = [Figure [C, A], Figure [C, B]]",
1200
1238
  "# <>",
1201
1239
  "```",
1240
+ "Repetition applies a Figure rather than concatenating, because a Figure",
1241
+ "declares its application: `3 U` is `(U U) U`, and each child it appends is `U`",
1242
+ "itself",
1243
+ "```",
1244
+ "; [(3 U) = ((U U) U), ((3 U).children .0) === Z, ((3 U).children .2) === U]",
1245
+ "# [<>, <>, <>]",
1246
+ "```",
1202
1247
  "## Manyness and Size",
1203
1248
  "",
1204
1249
  "Manyness marks the immediate children and looks no deeper",
@@ -1207,9 +1252,9 @@ export const HC_SOURCES = new Map([
1207
1252
  "# [<>, <>, <>, ()]",
1208
1253
  "```",
1209
1254
  "Size is recursive cell volume. `Z` is `A` and `U` is `B`, the same mark",
1210
- "Manyness uses, so a count is itself a Figure of units. Size maps each child to its Size and joins them into",
1211
- "`Tally Z`; the unit case comes first because a unit's only child is `Z`, and it",
1212
- "tests form, so any Figure shaped like `U` is a cell",
1255
+ "Manyness uses, so a count is itself a Figure of units. Size counts the cells",
1256
+ "with Cells and repeats `U` that many times. Cells tests form, so any Figure",
1257
+ "shaped like `U` is a cell",
1213
1258
  "```",
1214
1259
  "; [Z === A, U === B]",
1215
1260
  "# [<>, <>]",
@@ -1221,14 +1266,48 @@ export const HC_SOURCES = new Map([
1221
1266
  "# [<>, <>, <>]",
1222
1267
  "; [(row4.many()) = (row4.size()), (deep4.many()) = (deep4.size()), (two_fours.many()) = row2]",
1223
1268
  "# [<>, (), <>]",
1224
- "; ((Tally Z).row) = Z",
1225
- "# <>",
1269
+ "```",
1270
+ "Tallies add without a helper: the Size of a Figure holding two tallies joins",
1271
+ "them, and two `Z`s add to `Z`. Add two at a time, because two children are",
1272
+ "never shaped like `U`. One child can be: `Figure [Z]` has the form of `U`, so",
1273
+ "its Size is one cell, the rule that makes Multiplication and Tally",
1274
+ "multiplication guard `Z`",
1275
+ "```",
1276
+ "; [((Figure [row2, row3]).size()) = (row3.children | row2), ((Figure [Z, Z]).size()) = Z, ((Figure [Z]).size()) = (Figure [U])]",
1277
+ "# [<>, <>, <>]",
1278
+ "```",
1279
+ "Size answers `Z` itself for a Figure with no cells, and every unit of a Size is",
1280
+ "`U` itself, because repetition shares what it repeats",
1281
+ "```",
1282
+ "; [(Z.size()) === Z, ((Figure [Z, Z]).size()) === Z, ((U.size()).children .0) === U]",
1283
+ "# [<>, <>, <>]",
1226
1284
  "```",
1227
1285
  "A tally is its own Size, so Size is idempotent",
1228
1286
  "```",
1229
1287
  "; ((two_fours.size()).size()) = (two_fours.size())",
1230
1288
  "# <>",
1231
1289
  "```",
1290
+ "Counting first keeps a large Size quick: 256 cells, built by Multiplication",
1291
+ "```",
1292
+ "; .row16 (row4.mul row4); .row256 (row16.mul row16);",
1293
+ "; [(row256.size()).children.#, ((row256.size()).children .255) === U]",
1294
+ "# [256, <>]",
1295
+ "```",
1296
+ "A tally reads as a natural number, because its children are an aggregate and",
1297
+ "`.#` counts them. A Figure's own `.#` and `.##` are `0`: its children are a",
1298
+ "property, not its elements, and `.##` counts only what is not an aggregate",
1299
+ "```",
1300
+ "; [E.children.#, (E.many()).children.#, (two_fours.size()).children.#, E.#, E.##, E.children.##] = [2, 2, 8, 0, 0, 0]",
1301
+ "# <>",
1302
+ "```",
1303
+ "Cells marks where the cells are, and `.##` counts them as Size does. A count",
1304
+ "is its own size, as a tally is its own Size",
1305
+ "```",
1306
+ "; [(E.cells()) = [[], 1], (deep4.cells()) = [[[[1, 1, 1, 1]]]], (Z.cells()) = [], (U.cells()) = 1]",
1307
+ "# [<>, <>, <>, <>]",
1308
+ "; [(two_fours.cells()).##, (deep4.cells()).##, ((two_fours.cells()).##).##, (two_fours.size()).children.#] = [8, 4, 8, 8]",
1309
+ "# <>",
1310
+ "```",
1232
1311
  "## The semiring",
1233
1312
  "",
1234
1313
  "The carrier is not raw Figures. Let `F` be the finite, well-founded Figures,",
@@ -1256,6 +1335,11 @@ export const HC_SOURCES = new Map([
1256
1335
  "```",
1257
1336
  "; [((Figure [row2, row3]).size()) = (Figure [U, U, U, U, U]), (rectangle23.size()) = ((row2.size()).size_mul (row3.size()))]",
1258
1337
  "# [<>, <>]",
1338
+ "```",
1339
+ "At a zero factor both recipes answer `Z`, a one-cell factor included",
1340
+ "```",
1341
+ "; [(U.size_mul Z) = Z, ((Figure [U]).size_mul Z) = Z, ((U.mul Z).size()) = ((U.size()).size_mul (Z.size()))]",
1342
+ "# [<>, <>, <>]",
1259
1343
  "; .deep2 (Figure [Figure [row2]]); .deep3 (Figure [Figure [Figure [row3]]]);",
1260
1344
  "; [row2.size_equivalent deep2, row3.size_equivalent deep3, (Figure [row2, row3]).size_equivalent (Figure [deep2, deep3]), (row2.mul row3).size_equivalent (deep2.mul deep3)] = [U, U, U, U]",
1261
1345
  "# <>",
@@ -1270,6 +1354,12 @@ export const HC_SOURCES = new Map([
1270
1354
  "# [(), <>]",
1271
1355
  "; [(Figure [Z, row2]).size_equivalent row2, (Figure [row2, Z]).size_equivalent row2, (U.mul row2).size_equivalent row2, (row2.mul U).size_equivalent row2] = [U, U, U, U]",
1272
1356
  "# <>",
1357
+ "```",
1358
+ "Read as natural numbers, Size takes construction to `+` and multiplication to",
1359
+ "`*`, so the same laws hold of FrameCount arithmetic, where they are native",
1360
+ "```",
1361
+ "; [((Figure [row2, row3]).cells()).## = (((row2.cells()).##) + ((row3.cells()).##)), (rectangle23.cells()).## = (((row2.cells()).##) * ((row3.cells()).##))]",
1362
+ "# [<>, <>]",
1273
1363
  "; [(Figure [Figure [row2, row3], row4]).size_equivalent (Figure [row2, Figure [row3, row4]]), (Figure [row2, row3]).size_equivalent (Figure [row3, row2])] = [U, U]",
1274
1364
  "# <>",
1275
1365
  "; (((row2.mul row3).mul row4).size_equivalent (row2.mul (row3.mul row4))) = U",
@@ -1326,6 +1416,12 @@ export const HC_SOURCES = new Map([
1326
1416
  "; point_table = (originals.children & {.p _; originals.children & {(p === _) ? {Three} : {Figure [U]}}})",
1327
1417
  "# <>",
1328
1418
  "```",
1419
+ "Read as natural numbers, the table counts three on the diagonal and one",
1420
+ "everywhere else",
1421
+ "```",
1422
+ "; (point_table & {_ & {_.children.#}}) = (originals.children & {.p _; originals.children & {(p === _) ? {3} : {1}}})",
1423
+ "# <>",
1424
+ "```",
1329
1425
  "Dually, `meet` counts the originals two triples share: multiplying their two",
1330
1426
  "Withness marks leaves one cell exactly when both hold it. The two tables are",
1331
1427
  "equal, which is the plane's self-duality",
@@ -1356,7 +1452,8 @@ export const HC_SOURCES = new Map([
1356
1452
  "",
1357
1453
  "A bare name inside a block that a map applies to Figures reads each Figure's",
1358
1454
  "own members first (spec 7), so it cannot reach the method's. That is why a",
1359
- "method names its own Figure `_^` and binds `kids` before its blocks read it",
1455
+ "method names its own Figure `_^` and binds `kids` or `n` before its blocks read",
1456
+ "it",
1360
1457
  "```",
1361
1458
  "; (E.children & {children}) = [A.children, B.children]",
1362
1459
  "# <>",
@@ -1366,9 +1463,9 @@ export const HC_SOURCES = new Map([
1366
1463
  "the scope that built it. The Fano plane above already binds `f`, the name",
1367
1464
  "Withness uses inside its blocks; these bind the other locals",
1368
1465
  "```",
1369
- "; .kids 9; .y 9; .cells 9; .found 9; .absent 9;",
1370
- "; [(E.withness [A, B]) = B, (row2.mul row3) = rectangle23, (E.size()) = (Figure [U])]",
1371
- "# [<>, <>, <>]",
1466
+ "; .kids 9; .y 9; .n 9; .cells 9; .found 9; .absent 9;",
1467
+ "; [(E.withness [A, B]) = B, (row2.mul row3) = rectangle23, (E.size()) = (Figure [U]), (row2.size_mul row3) = (rectangle23.size())]",
1468
+ "# [<>, <>, <>, <>]",
1372
1469
  "```",
1373
1470
  "A method's free names resolve where the method was written, never where its",
1374
1471
  "receiver was read (#400). So a scope that binds its own `B` and reads a Figure",
@@ -1621,8 +1718,8 @@ export const HC_SOURCES = new Map([
1621
1718
  "```",
1622
1719
  "Imported methods compose with Figures built in this file, each with",
1623
1720
  "`Figures.Figure`. Size counts the cells of a Figure sum and of a Figure product.",
1624
- "On tallies, joining is a reduce, `ys | x`. `size_mul` multiplies, and `Tally Z`",
1625
- "collects a reduce",
1721
+ "On tallies, joining is a reduce, `ys | x`, `size_mul` multiplies, and the Size",
1722
+ "of a Figure holding two tallies adds them",
1626
1723
  "```",
1627
1724
  "; .duo (Figures.Figure [Figures.U, Figures.U]);",
1628
1725
  "; .trio (Figures.Figure [Figures.U, Figures.U, Figures.U]);",
@@ -1631,7 +1728,7 @@ export const HC_SOURCES = new Map([
1631
1728
  "# [<>, <>, <>]",
1632
1729
  "; (trio.children | (Figures.Figure [Figures.U])) = (Figures.Figure [Figures.U, Figures.U, Figures.U, Figures.U])",
1633
1730
  "# <>",
1634
- "; (([Figures.Figure [Figures.U], Figures.Figure [Figures.U]] | (Figures.Tally Figures.Z)).row) = duo",
1731
+ "; ((Figures.Figure [Figures.Figure [Figures.U], Figures.Figure [Figures.U]]).size()) = duo",
1635
1732
  "# <>",
1636
1733
  "```",
1637
1734
  "Identity crosses the import boundary. Withness asks for immediate containment",
@@ -1751,6 +1848,25 @@ export const HC_SOURCES = new Map([
1751
1848
  "# “HelloHelloHello”",
1752
1849
  "",
1753
1850
  "```",
1851
+ "Repeating an aggregate concatenates its elements (v0.22.0). The answer is a",
1852
+ "fresh aggregate of the same kind holding the receiver's properties once and its",
1853
+ "elements n times, shared rather than copied, so the receiver is never answered",
1854
+ "or written and no element holds its own aggregate",
1855
+ "```",
1856
+ "; 3 [1, 2]",
1857
+ "# [1, 2, 1, 2, 1, 2]",
1858
+ "; 0 [1, 2]",
1859
+ "# []",
1860
+ "; 2 [.k 1; 4, 5]",
1861
+ "# [.k 1; 4, 5, 4, 5]",
1862
+ "; 2 (1, 2)",
1863
+ "# (1, 2, 1, 2)",
1864
+ "; .xs [1, 2];",
1865
+ "; [3 xs, xs]",
1866
+ "# [[1, 2, 1, 2, 1, 2], [1, 2]]",
1867
+ "; [(1 xs) = xs, (1 xs) === xs, ((3 [xs]) .2) === xs, (2 [[1, 2]]).##]",
1868
+ "# [<>, (), <>, 4]",
1869
+ "```",
1754
1870
  "Cross-rung promotion and integer-only modulo",
1755
1871
  "```",
1756
1872
  "; 1 + 2.5",
@@ -1788,6 +1904,20 @@ export const HC_SOURCES = new Map([
1788
1904
  "; 2 ** 1000000",
1789
1905
  "# $!.numeric-range ** FrameCount",
1790
1906
  "```",
1907
+ "An aggregate's repetition applies nothing, so the application bound leaves it",
1908
+ "alone. Its answer is bounded instead, at 1,000,000 elements, and refused with",
1909
+ "the error repeated text uses. A negative or fractional count fails as it does",
1910
+ "for text",
1911
+ "```",
1912
+ "; (65537 [1]).#",
1913
+ "# 65537",
1914
+ "; 1000001 [1]",
1915
+ "# $!.repetition-size 1000000",
1916
+ "; (0 - 1) [1]",
1917
+ "# $!.repetition-count -1",
1918
+ "; 3.14 [1]",
1919
+ "# $!.repetition-domain FrameDecimal",
1920
+ "```",
1791
1921
  "Counts (#407). Every nonnegative integer literal is a `FrameCount`, the root of",
1792
1922
  "the ladder, and prints as the same integer does. A sequence's refusal names the",
1793
1923
  "class of its other operand, which is how these examples observe the rung",
@@ -59,6 +59,13 @@ export class FrameExpr extends FrameList {
59
59
  call(argument, parameter = Frame.nil) {
60
60
  return this.in(EvaluationScope.call(argument, parameter));
61
61
  }
62
+ /**
63
+ * An expression or a closure is called, not collected, so its terms are code
64
+ * rather than elements to concatenate: repetition applies it, as before.
65
+ */
66
+ repetitionFor(_count) {
67
+ return undefined;
68
+ }
62
69
  toStringDataArray() {
63
70
  const body = this.data
64
71
  .map((obj) => renderNested(obj, () => obj.toString()))
@@ -36,6 +36,14 @@ export class FrameGroup extends FrameList {
36
36
  this.data = this.data.map((frame) => frame.in(scope));
37
37
  return this;
38
38
  }
39
+ /**
40
+ * `()` is nil, so a repetition left with no term at all answers nil:
41
+ * `0 (1, 2)` is `()`, as the literal is. A group that holds properties keeps
42
+ * them, as every aggregate does, so `0 (.k 1; 4, 5)` holds `.k` alone.
43
+ */
44
+ finishRepetition() {
45
+ return this.size() === 0 ? Frame.nil : this;
46
+ }
39
47
  }
40
48
  Object.defineProperty(FrameGroup, "SIGIL_STARTS", {
41
49
  enumerable: true,
@@ -80,10 +80,16 @@ export class FrameInt extends FrameNumeric {
80
80
  ? count
81
81
  : Array.from({ length: count }, (_, index) => index);
82
82
  }
83
+ /** The refusal of a negative count, which every repetition answers first. */
84
+ negativeCount() {
85
+ return this.data < 0n
86
+ ? Frame.error(`$!.repetition-count ${this.spelling}`)
87
+ : undefined;
88
+ }
83
89
  repetitionCount() {
84
- if (this.data < 0n) {
85
- return Frame.error(`$!.repetition-count ${this.spelling}`);
86
- }
90
+ const negative = this.negativeCount();
91
+ if (negative)
92
+ return negative;
87
93
  if (this.data > REPETITION_LIMIT) {
88
94
  return Frame.error(`$!.repetition-limit ${REPETITION_LIMIT}`);
89
95
  }
@@ -170,6 +176,14 @@ export class FrameInt extends FrameNumeric {
170
176
  return this.data < value ? -1 : this.data > value ? 1 : 0;
171
177
  }
172
178
  repeat(argument, parameter) {
179
+ const negative = this.negativeCount();
180
+ if (negative)
181
+ return negative;
182
+ // An aggregate concatenates rather than applying itself (v0.22.0), and
183
+ // bounds the elements it answers rather than applications it performs.
184
+ const own = argument.referent().repetitionFor(this.data);
185
+ if (own !== undefined)
186
+ return own;
173
187
  const count = this.repetitionCount();
174
188
  if (count instanceof Frame)
175
189
  return count;
@@ -2,6 +2,7 @@ import { Frame } from "./frame.js";
2
2
  import { NilContext } from "./context.js";
3
3
  import { EvaluationScope } from "./evaluation-scope.js";
4
4
  import { FrameCount } from "./frame-count.js";
5
+ import { REPETITION_ELEMENT_LIMIT } from "./frame-numeric.js";
5
6
  import { renderNested } from "./stringify.js";
6
7
  /**
7
8
  * The declaration a term recorded, when it is a declaration echo.
@@ -104,7 +105,11 @@ export class FrameList extends Frame {
104
105
  * iterate.
105
106
  */
106
107
  elements() {
107
- return this.data.filter((item) => item.is.statement !== true && !this.holdsAsProperty(item));
108
+ return this.data.filter((item) => this.isElement(item));
109
+ }
110
+ /** Whether this term is one of the elements, as `elements()` reads them. */
111
+ isElement(term) {
112
+ return term.is.statement !== true && !this.holdsAsProperty(term);
108
113
  }
109
114
  /**
110
115
  * `.#` counts this aggregate's elements and `.##` the leaves below them
@@ -142,6 +147,55 @@ export class FrameList extends Frame {
142
147
  path.delete(this);
143
148
  return leaves;
144
149
  }
150
+ /**
151
+ * `n x` for an aggregate concatenates (v0.22.0). The answer is a fresh
152
+ * aggregate of x's kind holding the terms x keeps once, its properties and
153
+ * statements, followed by the terms it repeats, its elements, n times in
154
+ * order. The repeated terms are shared, as a collect shares what it
155
+ * collects, so each keeps its identity. x itself is never answered or
156
+ * written, so repeating a value builds no cycle. Properties stay once, as a
157
+ * reduce keeps only its receiver's: `[3, 4] | xs` concatenates into a copy
158
+ * of `xs`.
159
+ *
160
+ * An aggregate that declares its own application (#375) answers none, so
161
+ * repetition runs that application, as before. No application is performed
162
+ * here, so the answer is bounded by its size, at `REPETITION_ELEMENT_LIMIT`
163
+ * repeated terms, and refused with the error repeated text uses.
164
+ */
165
+ repetitionFor(count) {
166
+ if (this.applicationMethod() !== undefined)
167
+ return undefined;
168
+ const repeated = this.data.filter((term) => this.repeatsTerm(term));
169
+ if (BigInt(repeated.length) * count > REPETITION_ELEMENT_LIMIT) {
170
+ return Frame.error(`$!.repetition-size ${REPETITION_ELEMENT_LIMIT}`);
171
+ }
172
+ const result = this.copy();
173
+ const terms = result.data.filter((term) => !result.repeatsTerm(term));
174
+ // Within the limit, the loop runs at most that many times, and an
175
+ // aggregate with nothing to repeat skips it however large the count is.
176
+ const times = repeated.length === 0 ? 0 : Number(count);
177
+ for (let time = 0; time < times; time += 1) {
178
+ for (const term of repeated)
179
+ terms.push(term);
180
+ }
181
+ result.data = terms;
182
+ return result.finishRepetition();
183
+ }
184
+ /**
185
+ * Whether repetition repeats this term, rather than keeping it once. An
186
+ * aggregate repeats its elements and keeps its properties and statements
187
+ * once, as a reduce into it would.
188
+ */
189
+ repeatsTerm(term) {
190
+ return this.isElement(term);
191
+ }
192
+ /**
193
+ * What a repetition answers once its terms are in place: this aggregate,
194
+ * unless its kind has no value of that shape.
195
+ */
196
+ finishRepetition() {
197
+ return this;
198
+ }
145
199
  /**
146
200
  * The value a term answered, looking through a statement's wrapper.
147
201
  *
@@ -16,6 +16,8 @@ export const NUMERIC_RANK = {
16
16
  export const REPETITION_LIMIT = 65536n;
17
17
  /** The largest UTF-16 text result accepted by integer repetition. */
18
18
  export const REPETITION_TEXT_LIMIT = 1000000n;
19
+ /** The largest element count an aggregate's repetition may answer. */
20
+ export const REPETITION_ELEMENT_LIMIT = 1000000n;
19
21
  /** Maximum estimated bit width of an exact power result. */
20
22
  export const EXACT_POWER_BIT_LIMIT = 1000000n;
21
23
  /** Whether bigint exponentiation can stay within the exact-result budget. */
@@ -36,6 +36,32 @@ export class FrameSchema extends FrameList {
36
36
  const result = this.match(argument, parameter);
37
37
  return result.matched ? result.evidence : result.error;
38
38
  }
39
+ /**
40
+ * A schema's terms are all type terms, so repetition repeats every one, a
41
+ * statement too: `<.x; .y;>` and `<.x, .y>` are one type and repeat alike.
42
+ * A schema holds no properties, so only a held echo, were there one, would
43
+ * stay once.
44
+ */
45
+ repeatsTerm(term) {
46
+ return !this.holdsAsProperty(term);
47
+ }
48
+ /**
49
+ * A repeated schema matches what the literal with its terms written n times
50
+ * matches. With no term left that literal is `<>`, the total type. An
51
+ * enumeration matches by its terms, so it keeps its matcher. A compiled
52
+ * matcher was built from the terms, so it is rebuilt from the repeated ones;
53
+ * otherwise the schema would print and match as the one it repeated.
54
+ * `2 <.x, .y>` is `<.x, .y, .x, .y>`.
55
+ */
56
+ finishRepetition() {
57
+ if (this.size() === 0)
58
+ return Frame.all;
59
+ if (!(this.matcher instanceof EnumerationSchemaMatcher)) {
60
+ this.matcher = compileSchemaMatcher(this.data) ??
61
+ new EnumerationSchemaMatcher();
62
+ }
63
+ return this;
64
+ }
39
65
  match(value, origin = Frame.nil) {
40
66
  return this.matcher.match(this, value, origin);
41
67
  }
@@ -217,6 +217,16 @@ export class Frame extends MetaFrame {
217
217
  sizeFor(_key) {
218
218
  return Frame.nil;
219
219
  }
220
+ /**
221
+ * What integer repetition `n x` answers when this frame, x, has a rule of
222
+ * its own, or undefined when x is repeated by application: `FrameInt.repeat`
223
+ * then starts from nil and applies the running answer to x, n times. Only an
224
+ * aggregate has a rule (`FrameList`), so the base answers none. The caller
225
+ * has already refused a negative count.
226
+ */
227
+ repetitionFor(_count) {
228
+ return undefined;
229
+ }
220
230
  /**
221
231
  * Get a frame by key from this frame's own properties and its declared
222
232
  * parents only, never its lexical scope.
@@ -1 +1 @@
1
- export const VERSION = "0.21.1";
1
+ export const VERSION = "0.22.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",