hclang 0.23.2 → 0.24.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.
@@ -468,6 +468,35 @@ export const HC_SOURCES = new Map([
468
468
  "; [([1, 2] & r) = m, r]",
469
469
  "# [<>, [0]]",
470
470
  "```",
471
+ "## A splice joins the answers",
472
+ "",
473
+ "**Decision.** `&|` is the third thing that can become of each answer (#421).",
474
+ "It applies each element as `&` does, to a fresh copy of the receiver, and",
475
+ "splices the answers into one fresh array: each answer contributes its elements,",
476
+ "in order and shared. Anything which is not an aggregate is its own single",
477
+ "element, and nil contributes nothing. So concatenation is a splice of the",
478
+ "aggregates themselves, and filtering is a splice of a conditional",
479
+ "```",
480
+ "; [[1], [2, 3], []] &| {_}",
481
+ "# [1, 2, 3]",
482
+ "; [1, 2, 3, 4] &| {(_ = 2) ? {__}}",
483
+ "# [2]",
484
+ "; [1, 2] &| {[_, _]}",
485
+ "# [1, 1, 2, 2]",
486
+ "; [1, 2] &| [0]",
487
+ "# [0, 1, 0, 2]",
488
+ "; .inner [9];",
489
+ "; [(([inner] &| {[_]}) .0) === inner, [] &| {_}]",
490
+ "# [<>, []]",
491
+ "```",
492
+ "A splice is native and linear, where a reduce into an accumulator that streams",
493
+ "each answer in would copy what it has so far at every step. Repetition is the",
494
+ "special case of one aggregate spliced n times: `3 [1, 2]` is",
495
+ "`[0, 1, 2] &| {[1, 2]}`",
496
+ "```",
497
+ "; (3 [1, 2]) = ([0, 1, 2] &| {[1, 2]})",
498
+ "# <>",
499
+ "```",
471
500
  "## A name applies like the value it names",
472
501
  "",
473
502
  "**Decision.** Naming a receiver does not change what applying it answers, so a",
@@ -1141,26 +1170,26 @@ export const HC_SOURCES = new Map([
1141
1170
  "never affects `=`. Every observer answers a Figure, never a number or a",
1142
1171
  "Boolean: `A`, with no children, means no, and `B` means yes. So every answer can",
1143
1172
  "be a child, a receiver, or an argument, and the class is closed under its own",
1144
- "methods. Only Cells, Form and Text leave the class, on purpose: Cells and Form",
1145
- "answer a plain bracket tree and Text spells one, for reading a Figure rather",
1146
- "than computing with it. A tally also reads as a natural number. Its children",
1147
- "are an aggregate, so `(x.size()).children.#` is the FrameCount it spells and",
1173
+ "methods. Only Cells, Form and Text leave the class, on purpose: Cells answers",
1174
+ "a plain array of Figures, Form a bracket tree, and Text spells one, for reading",
1175
+ "a Figure rather than computing with it.",
1176
+ "",
1177
+ "Three observers share one form: a stream, a mark for each thing in it, and one",
1178
+ "construction. Manyness marks each child, Size marks each cell, and",
1179
+ "Multiplication puts y at each cell. No observer counts. A number appears only",
1180
+ "when a tally is read as one: its children are an aggregate, so",
1181
+ "`(x.size()).children.#` is the FrameCount it spells, as `(x.cells()).#` is, and",
1148
1182
  "`x.children.#` counts x's children. A Figure's own `.#` and `.##` are `0`,",
1149
1183
  "because its children are a property rather than its elements (#407, #411).",
1184
+ "Before v0.24.0 Size, Multiplication and Tally multiplication counted cells",
1185
+ "natively and built from the count (#414), and before v0.22.0 Size joined its",
1186
+ "children's Sizes one unit at a time through a helper (#415).",
1150
1187
  "",
1151
- "Size, Multiplication and Tally multiplication count first and then construct.",
1152
- "Each computes a count n natively, with Cells and the size operators, and builds",
1153
- "`Figure (n [U])` or `Figure (n [y])`, with the guards for zero that their",
1154
- "paragraphs give. Repeating an aggregate concatenates its elements and shares",
1155
- "them, so `n [U]` is n units, each `U` itself. Before v0.22.0 Size joined its",
1156
- "children's Sizes one unit at a time, so tallies added by joining. Tallies still",
1157
- "are the natural numbers in unary, they still join, `ys | x`, and two of them",
1158
- "add as the Size of a Figure holding both, `(Figure [x, y]).size()`. Size now",
1159
- "trades the joining derivation for construction from a native count.",
1160
- "Repetition holds at most 1,000,000 elements, so Size, Multiplication and Tally",
1161
- "multiplication answer `$!.repetition-size 1000000` once their count passes",
1162
- "that. The joining Size had no such ceiling, but its time grew quadratically",
1163
- "with the cells.",
1188
+ "Three Figures play the roles of zero and one, and keeping them apart is what",
1189
+ "the guards below are for. `Z` is zero. `U` is the unit cell that Size counts.",
1190
+ "`Figure [U]` is the tally one, the Size of `U`. `U` is itself `Figure [Z]`,",
1191
+ "one row of nothing, so wrapping zero in one Figure makes a cell: construction",
1192
+ "of two or more Figures adds, and construction of one wraps (#415).",
1164
1193
  "",
1165
1194
  "A method names its own Figure `_^`, because a bare name is looked up on the",
1166
1195
  "argument first (spec 7), and the argument is usually another Figure. For the",
@@ -1187,44 +1216,39 @@ export const HC_SOURCES = new Map([
1187
1216
  "```;",
1188
1217
  " .many {Figure (_^.children & {B})};",
1189
1218
  "```",
1190
- "**Size**, `x.size()`: a tally with one unit cell `U` per cell. Any Figure shaped",
1191
- "like `U` is a cell. Size counts them with Cells, below, and repeats `U` that",
1192
- "many times, and a Figure with no cells answers `Z` itself. It keeps the cell",
1193
- "count and forgets shape, nesting, order, reuse and identity",
1219
+ "**Size**, `x.size()`: a tally with one unit cell `U` per cell, as Manyness has",
1220
+ "one mark per child. It keeps the cell count and forgets shape, nesting, order,",
1221
+ "reuse and identity",
1194
1222
  "```;",
1195
- " .size {.n ((_^.cells()).##); (n = 0) ? {Z} : {Figure (n [U])}};",
1196
- "```",
1197
- "**Cells**, `x.cells()`: the bracket tree of x with `1` in place of each cell,",
1198
- "so `(x.cells()).##` is the Size of x as a natural number, counted without",
1199
- "joining a tally. A count is its own size, so the `1` of a unit is already its",
1200
- "count. It keeps the cell count and where the cells are, and forgets identity.",
1201
- "The unit case comes first, because a unit's only child is `Z`",
1223
+ " .size {Figure (_^.cells() & {U})};",
1224
+ "```",
1225
+ "**Cells**, `x.cells()`: the cells of x, in order, each one itself. Any Figure",
1226
+ "shaped like `U` is a cell, and every other Figure's cells are its children's,",
1227
+ "spliced into one array by `&|` (#421). The unit case comes first, because a",
1228
+ "unit's only child is `Z`. It keeps the cells and their order, and forgets where",
1229
+ "they were. A block in a method counts carets lexically, so the cell itself is",
1230
+ "`_^^` inside the branch",
1202
1231
  "```;",
1203
1232
  " .cells {.kids _^.children;",
1204
- " (kids = U.children) ? {1} : {kids & {_.cells()}}};",
1233
+ " (kids = U.children) ? {[_^^]} : {kids &| {_.cells()}}};",
1205
1234
  "```",
1206
- "**Multiplication**, `x.mul y`: y once for every cell of x, counted as Size",
1207
- "counts them, and `Z` when y is `Z`. Repetition shares what it repeats, so it",
1208
- "keeps y's identity in every position, and it forgets x's shape",
1235
+ "**Multiplication**, `x.mul y`: y at every cell of x, and `Z` when y is `Z`. It",
1236
+ "keeps y's identity in every position, and it forgets x's shape. Without the",
1237
+ "guard, a one-cell x would answer `Figure [Z]`, which is a cell rather than zero",
1209
1238
  "```;",
1210
- " .mul {.y _; .n ((_^.cells()).##); (y = Z) ? {Z} : {Figure (n [y])}};",
1239
+ " .mul {.y _; .cells _^.cells(); (y = Z) ? {Z} : {Figure (cells & {y})}};",
1211
1240
  "```",
1212
1241
  "**Tally multiplication**, `x.size_mul y`: the Size of a Figure holding y once",
1213
- "per child of x. That is x's number of children times y's cells, so it is",
1214
- "counted rather than built, and it is `Z` when the product is `0`, a y of `Z`",
1215
- "included. Building the Figure would go wrong there, as Multiplication would",
1216
- "without its guard: one row of nothing, `Figure [Z]`, has the form of `U` and",
1217
- "would count as a cell. It keeps the cell count and forgets both shapes",
1242
+ "per child of x, and `Z` when y is `Z`, for the reason Multiplication guards. It",
1243
+ "keeps the cell count and forgets both shapes",
1218
1244
  "```;",
1219
- " .size_mul {.n ((_^.children.#) * ((_.cells()).##));",
1220
- " (n = 0) ? {Z} : {Figure (n [U])}};",
1245
+ " .size_mul {.y _; .kids _^.children;",
1246
+ " (y = Z) ? {Z} : {(Figure (kids & {y})).size()}};",
1221
1247
  "```",
1222
- "**Size-equivalence**, `x.size_equivalent y`: `U` when the two Sizes agree and",
1223
- "`Z` otherwise. It compares the two cell counts as natural numbers, which",
1224
- "agree exactly when the two tallies do, so it joins no tally. It keeps only",
1225
- "whether the cell counts agree",
1248
+ "**Size-equivalence**, `x.size_equivalent y`: `U` when the two Sizes are the",
1249
+ "same tally and `Z` otherwise. It keeps only whether the cell counts agree",
1226
1250
  "```;",
1227
- " .size_equivalent {(((_^.cells()).##) = ((_.cells()).##)) ? {U} : {Z}};",
1251
+ " .size_equivalent {((_^.size()) = (_.size())) ? {U} : {Z}};",
1228
1252
  "```",
1229
1253
  "**Sameness of form**, `x.sameform y`: `B` when `x = y`. It compares child by",
1230
1254
  "child and forgets identity and reuse",
@@ -1323,8 +1347,8 @@ export const HC_SOURCES = new Map([
1323
1347
  "# [<>, <>, <>, ()]",
1324
1348
  "```",
1325
1349
  "Size is recursive cell volume. `Z` is `A` and `U` is `B`, the same mark",
1326
- "Manyness uses, so a count is itself a Figure of units. Size counts the cells",
1327
- "with Cells and repeats `U` that many times. Cells tests form, so any Figure",
1350
+ "Manyness uses, so a count is itself a Figure of units. Size marks each of the",
1351
+ "cells Cells finds, as Manyness marks each child. Cells tests form, so any Figure",
1328
1352
  "shaped like `U` is a cell",
1329
1353
  "```",
1330
1354
  "; [Z === A, U === B]",
@@ -1347,18 +1371,20 @@ export const HC_SOURCES = new Map([
1347
1371
  "; [((Figure [row2, row3]).size()) = (row3.children | row2), ((Figure [Z, Z]).size()) = Z, ((Figure [Z]).size()) = (Figure [U])]",
1348
1372
  "# [<>, <>, <>]",
1349
1373
  "```",
1350
- "Size answers `Z` itself for a Figure with no cells, and every unit of a Size is",
1351
- "`U` itself, because repetition shares what it repeats",
1374
+ "Size constructs its answer, so a Figure with no cells has a Size equal to `Z`",
1375
+ "in form but not `Z` itself: having no cells and being zero are different facts,",
1376
+ "and Size promises the first. Every unit of a Size is `U` itself",
1352
1377
  "```",
1353
- "; [(Z.size()) === Z, ((Figure [Z, Z]).size()) === Z, ((U.size()).children .0) === U]",
1354
- "# [<>, <>, <>]",
1378
+ "; [(Z.size()) = Z, (Z.size()) === Z, ((Figure [Z, Z]).size()) = Z, ((U.size()).children .0) === U]",
1379
+ "# [<>, (), <>, <>]",
1355
1380
  "```",
1356
1381
  "A tally is its own Size, so Size is idempotent",
1357
1382
  "```",
1358
1383
  "; ((two_fours.size()).size()) = (two_fours.size())",
1359
1384
  "# <>",
1360
1385
  "```",
1361
- "Counting first keeps a large Size quick: 256 cells, built by Multiplication",
1386
+ "Construction from a stream is linear, so a large Size is quick: 256 cells,",
1387
+ "built by Multiplication",
1362
1388
  "```",
1363
1389
  "; .row16 (row4.mul row4); .row256 (row16.mul row16);",
1364
1390
  "; [(row256.size()).children.#, ((row256.size()).children .255) === U]",
@@ -1371,12 +1397,12 @@ export const HC_SOURCES = new Map([
1371
1397
  "; [E.children.#, (E.many()).children.#, (two_fours.size()).children.#, E.#, E.##, E.children.##] = [2, 2, 8, 0, 0, 0]",
1372
1398
  "# <>",
1373
1399
  "```",
1374
- "Cells marks where the cells are, and `.##` counts them as Size does. A count",
1375
- "is its own size, as a tally is its own Size",
1400
+ "Cells answers the cells themselves, in order, wherever they were nested, and",
1401
+ "`.#` reads how many there are, as it reads a tally",
1376
1402
  "```",
1377
- "; [(E.cells()) = [[], 1], (deep4.cells()) = [[[[1, 1, 1, 1]]]], (Z.cells()) = [], (U.cells()) = 1]",
1378
- "# [<>, <>, <>, <>]",
1379
- "; [(two_fours.cells()).##, (deep4.cells()).##, ((two_fours.cells()).##).##, (two_fours.size()).children.#] = [8, 4, 8, 8]",
1403
+ "; [(E.cells()) = [B], ((E.cells()) .0) === B, (deep4.cells()) = row4.children, (Z.cells()) = [], ((U.cells()) .0) === U]",
1404
+ "# [<>, <>, <>, <>, <>]",
1405
+ "; [(two_fours.cells()).#, (deep4.cells()).#, (two_fours.size()).children.#] = [8, 4, 8]",
1380
1406
  "# <>",
1381
1407
  "```",
1382
1408
  "## The semiring",
@@ -1402,7 +1428,9 @@ export const HC_SOURCES = new Map([
1402
1428
  "# [<>, <>]",
1403
1429
  "```",
1404
1430
  "Size takes construction to joining and multiplication to `size_mul`, so both",
1405
- "recipes respect `≈`; the checks also use differently nested, equal-Size inputs",
1431
+ "recipes respect `≈`; the checks also use differently nested, equal-Size inputs.",
1432
+ "Size, `size_mul` and `size_equivalent` all construct, and none counts, so every",
1433
+ "check here and below compares two constructions (#415)",
1406
1434
  "```",
1407
1435
  "; [((Figure [row2, row3]).size()) = (Figure [U, U, U, U, U]), (rectangle23.size()) = ((row2.size()).size_mul (row3.size()))]",
1408
1436
  "# [<>, <>]",
@@ -1427,10 +1455,12 @@ export const HC_SOURCES = new Map([
1427
1455
  "# <>",
1428
1456
  "```",
1429
1457
  "Read as natural numbers, Size takes construction to `+` and multiplication to",
1430
- "`*`, so the same laws hold of FrameCount arithmetic, where they are native",
1458
+ "`*`, so the same laws hold of FrameCount arithmetic, where they are native.",
1459
+ "Each side reads a tally that was constructed, so the reading checks the",
1460
+ "construction rather than replacing it",
1431
1461
  "```",
1432
- "; [((Figure [row2, row3]).cells()).## = (((row2.cells()).##) + ((row3.cells()).##)), (rectangle23.cells()).## = (((row2.cells()).##) * ((row3.cells()).##))]",
1433
- "# [<>, <>]",
1462
+ "; [((Figure [row2, row3]).size()).children.# = (((row2.size()).children.#) + ((row3.size()).children.#)), (rectangle23.size()).children.# = (((row2.size()).children.#) * ((row3.size()).children.#)), (rectangle23.size()).children.# = 6]",
1463
+ "# [<>, <>, <>]",
1434
1464
  "; [(Figure [Figure [row2, row3], row4]).size_equivalent (Figure [row2, Figure [row3, row4]]), (Figure [row2, row3]).size_equivalent (Figure [row3, row2])] = [U, U]",
1435
1465
  "# <>",
1436
1466
  "; (((row2.mul row3).mul row4).size_equivalent (row2.mul (row3.mul row4))) = U",
@@ -40,6 +40,17 @@ const members = (source) => {
40
40
  * otherwise collect every element and be answered each time.
41
41
  */
42
42
  export const MapElements = (source, receiver, receiverState) => new FrameArray(source.elements().map((value) => receiver.collectingCopy().call(value, Frame.nil, receiverState)));
43
+ /**
44
+ * `&|` applies each element on its own, as `&` does, and splices the answers
45
+ * into one fresh array: each answer contributes its elements, in order and
46
+ * shared, and a nil answer contributes nothing (#421). Anything which is not
47
+ * an aggregate is its own single element, so `xs &| {_}` concatenates the
48
+ * aggregates xs holds, and a block that answers nil for some elements filters.
49
+ */
50
+ export const SpliceElements = (source, receiver, receiverState) => new FrameArray(source.elements().flatMap((value) => {
51
+ const answer = receiver.collectingCopy().call(value, Frame.nil, receiverState);
52
+ return answer.is.void ? [] : answer.elements();
53
+ }));
43
54
  /** `|` threads each element through the receiver the last step answered. */
44
55
  export const ReduceElements = (source, receiver, receiverState) => source.reduce(receiver, receiverState);
45
56
  /** `&&` maps the same stream widened to `[key, value]` tuples, as `&` does. */
package/esm/lib/ops.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { IfElse, IfThen } from "./ops/conditionals.js";
2
2
  import { FrameOps } from "./ops/frame-ops.js";
3
- import { MapElements, MapMembers, ReduceElements, ReduceMembers, } from "./ops/iterators.js";
3
+ import { MapElements, MapMembers, ReduceElements, ReduceMembers, SpliceElements, } from "./ops/iterators.js";
4
4
  import { Add, Divide, Equals, GreaterThan, GreaterThanOrEqual, Identical, LessThan, LessThanOrEqual, Modulo, Multiply, Power, Subtract, TypeEquals, } from "./ops/math.js";
5
5
  import { BindType, HasType } from "./ops/type-operations.js";
6
6
  export { FrameCurry } from "./ops/frame-curry.js";
7
7
  export const Ops = new FrameOps({
8
8
  "&": MapElements,
9
9
  "&&": MapMembers,
10
+ "&|": SpliceElements,
10
11
  ":": IfElse,
11
12
  "?": IfThen,
12
13
  "|": ReduceElements,
@@ -1 +1 @@
1
- export const VERSION = "0.23.2";
1
+ export const VERSION = "0.24.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.23.2",
3
+ "version": "0.24.0",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",