hclang 0.23.1 → 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.
- package/esm/lib/bundle/hc-sources.js +122 -67
- package/esm/lib/frames/evaluation-scope.js +10 -0
- package/esm/lib/frames/frame-arg.js +1 -1
- package/esm/lib/frames/frame-array.js +8 -0
- package/esm/lib/frames/frame-handle.js +4 -0
- package/esm/lib/frames/frame-int.js +6 -1
- package/esm/lib/frames/frame.js +8 -0
- package/esm/lib/ops/iterators.js +11 -0
- package/esm/lib/ops.js +2 -1
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -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",
|
|
@@ -496,6 +525,20 @@ export const HC_SOURCES = new Map([
|
|
|
496
525
|
"; [((row xs) .2) === xs, (row xs) === row]",
|
|
497
526
|
"# [<>, ()]",
|
|
498
527
|
"```",
|
|
528
|
+
"An argument applies like a name, too (#419). A value an operation is handed,",
|
|
529
|
+
"an element a map gives its block or the operand of a repetition, is read-only:",
|
|
530
|
+
"applying it collects onto a copy, and its declared `apply_` answers a",
|
|
531
|
+
"functional update. Only what the operation created, a fresh literal or a",
|
|
532
|
+
"reduce's own accumulator, is written in place",
|
|
533
|
+
"```",
|
|
534
|
+
"; .nest [[1], [2]];",
|
|
535
|
+
"; [nest & {_ 9}, nest]",
|
|
536
|
+
"# [[[1, 9], [2, 9]], [[1], [2]]]",
|
|
537
|
+
"; .Acc {[.n _; .apply_ {@n (_^.n + 1);}]};",
|
|
538
|
+
"; .acc (Acc 0);",
|
|
539
|
+
"; [(3 acc).n, acc.n]",
|
|
540
|
+
"# [2, 0]",
|
|
541
|
+
"```",
|
|
499
542
|
"Concatenation therefore needs no operator of its own: reduce one aggregate into",
|
|
500
543
|
"another, named or computed",
|
|
501
544
|
"```",
|
|
@@ -1127,26 +1170,26 @@ export const HC_SOURCES = new Map([
|
|
|
1127
1170
|
"never affects `=`. Every observer answers a Figure, never a number or a",
|
|
1128
1171
|
"Boolean: `A`, with no children, means no, and `B` means yes. So every answer can",
|
|
1129
1172
|
"be a child, a receiver, or an argument, and the class is closed under its own",
|
|
1130
|
-
"methods. Only Cells, Form and Text leave the class, on purpose: Cells
|
|
1131
|
-
"
|
|
1132
|
-
"than computing with it.
|
|
1133
|
-
"
|
|
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",
|
|
1134
1182
|
"`x.children.#` counts x's children. A Figure's own `.#` and `.##` are `0`,",
|
|
1135
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).",
|
|
1136
1187
|
"",
|
|
1137
|
-
"
|
|
1138
|
-
"
|
|
1139
|
-
"`Figure
|
|
1140
|
-
"
|
|
1141
|
-
"
|
|
1142
|
-
"children's Sizes one unit at a time, so tallies added by joining. Tallies still",
|
|
1143
|
-
"are the natural numbers in unary, they still join, `ys | x`, and two of them",
|
|
1144
|
-
"add as the Size of a Figure holding both, `(Figure [x, y]).size()`. Size now",
|
|
1145
|
-
"trades the joining derivation for construction from a native count.",
|
|
1146
|
-
"Repetition holds at most 1,000,000 elements, so Size, Multiplication and Tally",
|
|
1147
|
-
"multiplication answer `$!.repetition-size 1000000` once their count passes",
|
|
1148
|
-
"that. The joining Size had no such ceiling, but its time grew quadratically",
|
|
1149
|
-
"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).",
|
|
1150
1193
|
"",
|
|
1151
1194
|
"A method names its own Figure `_^`, because a bare name is looked up on the",
|
|
1152
1195
|
"argument first (spec 7), and the argument is usually another Figure. For the",
|
|
@@ -1159,11 +1202,13 @@ export const HC_SOURCES = new Map([
|
|
|
1159
1202
|
"```;",
|
|
1160
1203
|
" .children (_ | []);",
|
|
1161
1204
|
"```",
|
|
1162
|
-
"**Application**, `x y` (#375):
|
|
1163
|
-
"
|
|
1164
|
-
"
|
|
1205
|
+
"**Application**, `x y` (#375): x's children followed by y. It is a mutating",
|
|
1206
|
+
"method, `apply_`, so through a name, `x y` is a functional update: it answers a",
|
|
1207
|
+
"new Figure and leaves x unchanged. A reduce writes only the Figure its own",
|
|
1208
|
+
"first step answered, so `ys | x` joins two Figures, copying x once, and",
|
|
1209
|
+
"`cs | (Figure [])` constructs one out of a stream. It forgets nothing",
|
|
1165
1210
|
"```;",
|
|
1166
|
-
" .
|
|
1211
|
+
" .apply_ {@children (_^.children _);};",
|
|
1167
1212
|
"```",
|
|
1168
1213
|
"**Manyness**, `x.many()`: a tally with one mark `B` per immediate child. It",
|
|
1169
1214
|
"keeps how many children there are and forgets what they are, everything below",
|
|
@@ -1171,44 +1216,39 @@ export const HC_SOURCES = new Map([
|
|
|
1171
1216
|
"```;",
|
|
1172
1217
|
" .many {Figure (_^.children & {B})};",
|
|
1173
1218
|
"```",
|
|
1174
|
-
"**Size**, `x.size()`: a tally with one unit cell `U` per cell
|
|
1175
|
-
"
|
|
1176
|
-
"
|
|
1177
|
-
"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",
|
|
1178
1222
|
"```;",
|
|
1179
|
-
" .size {
|
|
1180
|
-
"```",
|
|
1181
|
-
"**Cells**, `x.cells()`: the
|
|
1182
|
-
"
|
|
1183
|
-
"
|
|
1184
|
-
"
|
|
1185
|
-
"
|
|
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",
|
|
1186
1231
|
"```;",
|
|
1187
1232
|
" .cells {.kids _^.children;",
|
|
1188
|
-
" (kids = U.children) ? {
|
|
1233
|
+
" (kids = U.children) ? {[_^^]} : {kids &| {_.cells()}}};",
|
|
1189
1234
|
"```",
|
|
1190
|
-
"**Multiplication**, `x.mul y`: y
|
|
1191
|
-
"
|
|
1192
|
-
"
|
|
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",
|
|
1193
1238
|
"```;",
|
|
1194
|
-
" .mul {.y _; .
|
|
1239
|
+
" .mul {.y _; .cells _^.cells(); (y = Z) ? {Z} : {Figure (cells & {y})}};",
|
|
1195
1240
|
"```",
|
|
1196
1241
|
"**Tally multiplication**, `x.size_mul y`: the Size of a Figure holding y once",
|
|
1197
|
-
"per child of x
|
|
1198
|
-
"
|
|
1199
|
-
"included. Building the Figure would go wrong there, as Multiplication would",
|
|
1200
|
-
"without its guard: one row of nothing, `Figure [Z]`, has the form of `U` and",
|
|
1201
|
-
"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",
|
|
1202
1244
|
"```;",
|
|
1203
|
-
" .size_mul {.
|
|
1204
|
-
" (
|
|
1245
|
+
" .size_mul {.y _; .kids _^.children;",
|
|
1246
|
+
" (y = Z) ? {Z} : {(Figure (kids & {y})).size()}};",
|
|
1205
1247
|
"```",
|
|
1206
|
-
"**Size-equivalence**, `x.size_equivalent y`: `U` when the two Sizes
|
|
1207
|
-
"`Z` otherwise. It
|
|
1208
|
-
"agree exactly when the two tallies do, so it joins no tally. It keeps only",
|
|
1209
|
-
"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",
|
|
1210
1250
|
"```;",
|
|
1211
|
-
" .size_equivalent {((
|
|
1251
|
+
" .size_equivalent {((_^.size()) = (_.size())) ? {U} : {Z}};",
|
|
1212
1252
|
"```",
|
|
1213
1253
|
"**Sameness of form**, `x.sameform y`: `B` when `x = y`. It compares child by",
|
|
1214
1254
|
"child and forgets identity and reuse",
|
|
@@ -1285,9 +1325,18 @@ export const HC_SOURCES = new Map([
|
|
|
1285
1325
|
"```",
|
|
1286
1326
|
"Repetition applies a Figure rather than concatenating, because a Figure",
|
|
1287
1327
|
"declares its application: `3 U` is `(U U) U`, and each child it appends is `U`",
|
|
1288
|
-
"itself",
|
|
1328
|
+
"itself. U is the operand, never the receiver written",
|
|
1289
1329
|
"```",
|
|
1290
|
-
"; [(3 U) = ((U U) U), ((3 U).children .0) === Z, ((3 U).children .2) === U]",
|
|
1330
|
+
"; [(3 U) = ((U U) U), ((3 U).children .0) === Z, ((3 U).children .2) === U, U = (Figure [Z])]",
|
|
1331
|
+
"# [<>, <>, <>, <>]",
|
|
1332
|
+
"```",
|
|
1333
|
+
"A join copies its receiver once and appends in place after that, so it is",
|
|
1334
|
+
"quick, and the receiver and every child keep their identity",
|
|
1335
|
+
"```",
|
|
1336
|
+
"; .joined ((512 [U]) | Z);",
|
|
1337
|
+
"; [joined.children.#, Z = (Figure []), (joined.children .511) === U]",
|
|
1338
|
+
"# [512, <>, <>]",
|
|
1339
|
+
"; [(E.children & {_ A}) = [Figure [A], Figure [Z, A]], A = (Figure []), B = (Figure [A])]",
|
|
1291
1340
|
"# [<>, <>, <>]",
|
|
1292
1341
|
"```",
|
|
1293
1342
|
"## Manyness and Size",
|
|
@@ -1298,8 +1347,8 @@ export const HC_SOURCES = new Map([
|
|
|
1298
1347
|
"# [<>, <>, <>, ()]",
|
|
1299
1348
|
"```",
|
|
1300
1349
|
"Size is recursive cell volume. `Z` is `A` and `U` is `B`, the same mark",
|
|
1301
|
-
"Manyness uses, so a count is itself a Figure of units. Size
|
|
1302
|
-
"
|
|
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",
|
|
1303
1352
|
"shaped like `U` is a cell",
|
|
1304
1353
|
"```",
|
|
1305
1354
|
"; [Z === A, U === B]",
|
|
@@ -1322,18 +1371,20 @@ export const HC_SOURCES = new Map([
|
|
|
1322
1371
|
"; [((Figure [row2, row3]).size()) = (row3.children | row2), ((Figure [Z, Z]).size()) = Z, ((Figure [Z]).size()) = (Figure [U])]",
|
|
1323
1372
|
"# [<>, <>, <>]",
|
|
1324
1373
|
"```",
|
|
1325
|
-
"Size
|
|
1326
|
-
"`
|
|
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",
|
|
1327
1377
|
"```",
|
|
1328
|
-
"; [(Z.size()) === Z, ((Figure [Z, Z]).size())
|
|
1329
|
-
"# [<>, <>, <>]",
|
|
1378
|
+
"; [(Z.size()) = Z, (Z.size()) === Z, ((Figure [Z, Z]).size()) = Z, ((U.size()).children .0) === U]",
|
|
1379
|
+
"# [<>, (), <>, <>]",
|
|
1330
1380
|
"```",
|
|
1331
1381
|
"A tally is its own Size, so Size is idempotent",
|
|
1332
1382
|
"```",
|
|
1333
1383
|
"; ((two_fours.size()).size()) = (two_fours.size())",
|
|
1334
1384
|
"# <>",
|
|
1335
1385
|
"```",
|
|
1336
|
-
"
|
|
1386
|
+
"Construction from a stream is linear, so a large Size is quick: 256 cells,",
|
|
1387
|
+
"built by Multiplication",
|
|
1337
1388
|
"```",
|
|
1338
1389
|
"; .row16 (row4.mul row4); .row256 (row16.mul row16);",
|
|
1339
1390
|
"; [(row256.size()).children.#, ((row256.size()).children .255) === U]",
|
|
@@ -1346,12 +1397,12 @@ export const HC_SOURCES = new Map([
|
|
|
1346
1397
|
"; [E.children.#, (E.many()).children.#, (two_fours.size()).children.#, E.#, E.##, E.children.##] = [2, 2, 8, 0, 0, 0]",
|
|
1347
1398
|
"# <>",
|
|
1348
1399
|
"```",
|
|
1349
|
-
"Cells
|
|
1350
|
-
"
|
|
1400
|
+
"Cells answers the cells themselves, in order, wherever they were nested, and",
|
|
1401
|
+
"`.#` reads how many there are, as it reads a tally",
|
|
1351
1402
|
"```",
|
|
1352
|
-
"; [(E.cells()) = [
|
|
1353
|
-
"# [<>, <>, <>, <>]",
|
|
1354
|
-
"; [(two_fours.cells())
|
|
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]",
|
|
1355
1406
|
"# <>",
|
|
1356
1407
|
"```",
|
|
1357
1408
|
"## The semiring",
|
|
@@ -1377,7 +1428,9 @@ export const HC_SOURCES = new Map([
|
|
|
1377
1428
|
"# [<>, <>]",
|
|
1378
1429
|
"```",
|
|
1379
1430
|
"Size takes construction to joining and multiplication to `size_mul`, so both",
|
|
1380
|
-
"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)",
|
|
1381
1434
|
"```",
|
|
1382
1435
|
"; [((Figure [row2, row3]).size()) = (Figure [U, U, U, U, U]), (rectangle23.size()) = ((row2.size()).size_mul (row3.size()))]",
|
|
1383
1436
|
"# [<>, <>]",
|
|
@@ -1402,10 +1455,12 @@ export const HC_SOURCES = new Map([
|
|
|
1402
1455
|
"# <>",
|
|
1403
1456
|
"```",
|
|
1404
1457
|
"Read as natural numbers, Size takes construction to `+` and multiplication to",
|
|
1405
|
-
"`*`, 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",
|
|
1406
1461
|
"```",
|
|
1407
|
-
"; [((Figure [row2, row3]).
|
|
1408
|
-
"# [<>, <>]",
|
|
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
|
+
"# [<>, <>, <>]",
|
|
1409
1464
|
"; [(Figure [Figure [row2, row3], row4]).size_equivalent (Figure [row2, Figure [row3, row4]]), (Figure [row2, row3]).size_equivalent (Figure [row3, row2])] = [U, U]",
|
|
1410
1465
|
"# <>",
|
|
1411
1466
|
"; (((row2.mul row3).mul row4).size_equivalent (row2.mul (row3.mul row4))) = U",
|
|
@@ -365,6 +365,16 @@ export class EvaluationScope {
|
|
|
365
365
|
}
|
|
366
366
|
return scope?.argument;
|
|
367
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* The argument `_`, `__`, ... as source reads it: an aggregate the call was
|
|
370
|
+
* handed raw is read through an immutable handle, as a name would read it,
|
|
371
|
+
* so applying it collects onto a copy and its mutating methods answer
|
|
372
|
+
* functional updates. An argument is never the call's to write (#419). A
|
|
373
|
+
* handle the caller passed, mutable or not, is kept as it is.
|
|
374
|
+
*/
|
|
375
|
+
argumentRead(level) {
|
|
376
|
+
return this.argumentAt(level)?.readOnly();
|
|
377
|
+
}
|
|
368
378
|
/** Resolves `.`, `..`, ... through exact enclosing call parameters. */
|
|
369
379
|
parameterAt(level) {
|
|
370
380
|
if (level <= 1)
|
|
@@ -38,7 +38,7 @@ export class FrameArg extends FrameSymbol {
|
|
|
38
38
|
in(input = []) {
|
|
39
39
|
const scope = EvaluationScope.from(input);
|
|
40
40
|
const level = this.data.length;
|
|
41
|
-
const target = scope.
|
|
41
|
+
const target = scope.argumentRead(level);
|
|
42
42
|
if (target)
|
|
43
43
|
return target;
|
|
44
44
|
// Outside a closure, an unresolved level remains an argument expression at
|
|
@@ -5,6 +5,7 @@ import { Frame } from "./frame.js";
|
|
|
5
5
|
import { BoundMethod } from "./bound-method.js";
|
|
6
6
|
import { methodEffect } from "./effect-marker.js";
|
|
7
7
|
import { FrameExpr } from "./frame-expr.js";
|
|
8
|
+
import { FrameHandle } from "./frame-handle.js";
|
|
8
9
|
import { FrameList } from "./frame-list.js";
|
|
9
10
|
import { FrameNote } from "./frame-note.js";
|
|
10
11
|
import { NilContext } from "./context.js";
|
|
@@ -61,6 +62,13 @@ export class FrameArray extends FrameList {
|
|
|
61
62
|
ownsIdentity() {
|
|
62
63
|
return true;
|
|
63
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* An immutable handle on this aggregate, as a name reads it: applying it
|
|
67
|
+
* collects onto a copy and its mutating methods answer functional updates.
|
|
68
|
+
*/
|
|
69
|
+
readOnly() {
|
|
70
|
+
return new FrameHandle(this, false);
|
|
71
|
+
}
|
|
64
72
|
/**
|
|
65
73
|
* `=` compares the complete view, the same one `&&` iterates: visible
|
|
66
74
|
* properties in declaration order, then elements by index, each by `=`.
|
|
@@ -98,6 +98,10 @@ export class FrameHandle extends Frame {
|
|
|
98
98
|
this.target = copy;
|
|
99
99
|
return copy;
|
|
100
100
|
}
|
|
101
|
+
/** A handle already says whether its reader may write; keep it as it is. */
|
|
102
|
+
readOnly() {
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
101
105
|
/** A handle is transparent to equality: it compares as its target. */
|
|
102
106
|
referent() {
|
|
103
107
|
return this.target.referent();
|
|
@@ -192,9 +192,14 @@ export class FrameInt extends FrameNumeric {
|
|
|
192
192
|
REPETITION_TEXT_LIMIT) {
|
|
193
193
|
return Frame.error(`$!.repetition-size ${REPETITION_TEXT_LIMIT}`);
|
|
194
194
|
}
|
|
195
|
+
// The operand arrives unwrapped, and applying to nil answers it as it is.
|
|
196
|
+
// Read it as a name would, so a later step that writes, such as a declared
|
|
197
|
+
// `apply_`, updates a copy rather than the operand itself (#419).
|
|
198
|
+
const operand = argument.readOnly();
|
|
195
199
|
let result = Frame.nil;
|
|
196
200
|
for (let index = 0; index < count; index += 1) {
|
|
197
|
-
|
|
201
|
+
const next = result.apply(operand, parameter);
|
|
202
|
+
result = next === operand.referent() ? operand : next;
|
|
198
203
|
}
|
|
199
204
|
return result;
|
|
200
205
|
}
|
package/esm/lib/frames/frame.js
CHANGED
|
@@ -253,6 +253,14 @@ export class Frame extends MetaFrame {
|
|
|
253
253
|
ownsIdentity() {
|
|
254
254
|
return false;
|
|
255
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* This frame as a value its reader may not write (#419). Only an aggregate
|
|
258
|
+
* owns identity a write can land on, so every other frame is its own
|
|
259
|
+
* read-only view; `FrameArray` answers an immutable handle on itself.
|
|
260
|
+
*/
|
|
261
|
+
readOnly() {
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
256
264
|
/** Compare only this frame's data plane, excluding metadata. */
|
|
257
265
|
dataEquals(other) {
|
|
258
266
|
return this.dataString() === other.dataString() ? Frame.all : Frame.nil;
|
package/esm/lib/ops/iterators.js
CHANGED
|
@@ -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,
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.24.0";
|