hclang 0.34.0 → 0.37.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.
@@ -228,7 +228,7 @@ export const HC_SOURCES = new Map([
228
228
  "",
229
229
  "The `<>` property retrieves the schema attached to the binding:",
230
230
  "```",
231
- "; enum123.<>",
231
+ "; enum123.<^>",
232
232
  "# <1, 2, 3>",
233
233
  "```",
234
234
  "",
@@ -693,16 +693,18 @@ export const HC_SOURCES = new Map([
693
693
  "`.#` and `.##` count the elements too, the immediate ones and the terminals",
694
694
  "below them, so neither counts a property. A terminal is an element that is not",
695
695
  "an aggregate, or an aggregate with no elements: the empty frame is one terminal,",
696
- "at the root or nested. Every aggregate counts this way, a group as well as an",
697
- "array. A count is its own size, and any other value has none (#411, issue",
696
+ "at the root or nested. A nested count contributes its own Size, including zero",
697
+ "(`[[3], 0].##` is 3); other atoms contribute one. Every aggregate counts this",
698
+ "way, a group as well as an array. A count is its own size, and any other value",
699
+ "has none (#411, issue",
698
700
  "occurrence/figure 010.02)",
699
701
  "```",
700
702
  "; [.meta 1; 2, 3] .#",
701
703
  "# 2",
702
704
  "; [.meta [1, 2]; [3, []], 4] .##",
703
- "# 3",
705
+ "# 8",
704
706
  "; (1, [2, 3]) .##",
705
- "# 3",
707
+ "# 6",
706
708
  "; [[].#, [].##, [[], [[], []]].#, [[], [[], []]].##]",
707
709
  "# [0, 1, 2, 3]",
708
710
  "; 5.#",
@@ -1165,7 +1167,7 @@ export const HC_SOURCES = new Map([
1165
1167
  "Figures are native frames (#454; issue occurrence/figure 010.02)",
1166
1168
  "",
1167
1169
  "A Figure is a finite nested array built from `[]`, read through its elements",
1168
- "only: properties and declared parents are ignored by observations. Inlay keeps",
1170
+ "only: properties and declared parents are ignored by observations. Star keeps",
1169
1171
  "nonterminal metadata when rebuilding frames. Construction is brackets, form is the value itself, immediate size is `.#`, terminal count",
1170
1172
  "is `.##`, form equality is `=`, and identity is `===`. The empty frame is one",
1171
1173
  "terminal: `[].#` is 0 and `[].##` is 1. The signed residual `.###` is",
@@ -1173,20 +1175,23 @@ export const HC_SOURCES = new Map([
1173
1175
  "for `[]` (issue occurrence/figure 010.04).",
1174
1176
  "",
1175
1177
  "There are no Figure constructors, marks, tally observers, count aliases or",
1176
- "comparison wrappers. Use native operations directly. Multiplication that places",
1177
- "y once per terminal of x is `x.## [y]`. A tally, when wanted, is an explicit",
1178
+ "comparison wrappers. Use native operations directly. Star `x * y` places y at each terminal of x, preserving nesting.",
1179
+ "Flat repetition is `x.## [y]`. A tally, when wanted, is an explicit",
1178
1180
  "construction, such as `x & {[[]]}` for one fresh mark per immediate element.",
1179
- "Native `.##` also counts atoms in mixed trees; native `.###` answers nil on",
1180
- "anything that is not a Figure, so this module's traversals stay in the domain.",
1181
+ "Native `.##` uses each child's native Size, including numeric magnitude and",
1182
+ "text length. Native `.###` also accepts mixed arrays and evaluated groups.",
1183
+ "Star keeps its narrower array/Count composition domain.",
1181
1184
  "",
1182
- "Only operations that add a traversal or calculation remain: `inlay`, `withness`, `gap` and `spin`, with `pure` and `need` for domain validation.",
1185
+ "Only observation operations remain: `withness`, `gap` and `spin`, with `pure` and `need` for domain validation.",
1183
1186
  "The traversals validate at their public boundary; their recursive steps use",
1184
1187
  "native operations directly. Withness returns a native boolean, `<>` or `()`.",
1185
1188
  "```",
1186
1189
  "```",
1187
- "Supported domain: `pure x` accepts nested arrays, ignoring their properties",
1188
- "and declared parents at every level, and rejects atoms, strings, groups, schemas and closures anywhere in them. It is",
1189
- "the native `.###` check: a FrameInt, even 0, is true, and nil is false.",
1190
+ "`pure x` retains its name for compatibility but now accepts the native residual",
1191
+ "domain: mixed arrays and evaluated groups with finite child Sizes. Properties",
1192
+ "and declared parents are ignored. Standalone atoms, schemas and closures have",
1193
+ "no residual. It is the native `.###` check: a FrameInt, even 0, is true,",
1194
+ "and nil is false. Helper retirement is deferred to occurrence/figure 010.09.",
1190
1195
  "```",
1191
1196
  ".pure {.x _; (x.###) ? {<>} : {()}};",
1192
1197
  "```",
@@ -1194,25 +1199,18 @@ export const HC_SOURCES = new Map([
1194
1199
  "```",
1195
1200
  ".need {.x _; (pure x) ? {x} : {unsupported-figure}};",
1196
1201
  "```",
1197
- "`inlay x y` replaces every terminal of x with y, retaining nonterminal nesting.",
1198
- "The replacement is reused by identity; ancestors are freshly constructed,",
1199
- "preserving their properties and declared parents. A terminal is recognized by",
1200
- "its element count; its replacement is y itself, including y’s metadata.",
1201
- "The host is validated once, and the replacement can be any native value.",
1202
- "```",
1203
- ".inlay {.x _; .host x;",
1204
- " (pure host) ? {",
1205
- " {.y _;",
1206
- " .go {.n _; (n.# = 0) ? {y} : {(n & {go _}) | (0 n)}};",
1207
- " go host}} : {",
1208
- " {.y _; need host}}};",
1209
- "```",
1202
+ "Native Star `x * y` replaces empty-array terminals with y and composes",
1203
+ "FrameCount leaves using the same rule as a root count, including zero.",
1204
+ "Replacements are shared by identity; ancestors preserve native metadata.",
1205
+ "Terminals carrying metadata or statements are refused to avoid losing them.",
1206
+ "Use `*` directly; the Figures module provides no composition wrapper.",
1207
+ "",
1210
1208
  "`withness x [f, …]` asks whether every requested frame is an immediate element",
1211
1209
  "of x by native identity. It returns a native boolean. No requested frames is true.",
1212
1210
  "```",
1213
1211
  ".withness {.x _; .host x;",
1214
1212
  " {.fs _;",
1215
- " .absent (fs &| {.f _; ((host &| {(_ === f) ? {[f]}}) = []) ? {[f]}});",
1213
+ " .absent (fs &| {.f _; (f ~~~ host) ? {[]} : {[f]}});",
1216
1214
  " absent = []}};",
1217
1215
  "```",
1218
1216
  "`gap x` is the absolute value of native `x.###`, the alternating sum of its",
@@ -1229,7 +1227,7 @@ export const HC_SOURCES = new Map([
1229
1227
  "```",
1230
1228
  ".spin {.x _; .host x;",
1231
1229
  " (pure host) ? {",
1232
- " {.n <~~1> _;",
1230
+ " {.n <(1).<>> _;",
1233
1231
  " .signed (host.###);",
1234
1232
  " (n .< 1) ? {signed / 0} : {signed / n}}} : {",
1235
1233
  " {.n _; need host}}};",
@@ -1247,43 +1245,43 @@ export const HC_SOURCES = new Map([
1247
1245
  "Native terminal counting needs no enumeration or tally construction.",
1248
1246
  "```",
1249
1247
  "; [(pure []), (pure [[], [[]]]), (pure [[], 5]), (pure [.k 1; []])]",
1250
- "# [<>, <>, (), <>]",
1248
+ "# [<>, <>, <>, <>]",
1251
1249
  "; [(need e) = e, (need e) === e]",
1252
1250
  "# [<>, <>]",
1253
- "; inlay [[], 5] [[]]",
1254
- "# $!.name-missing “$:Frame.0.unsupported-figure”;",
1255
- "; inlay 5 [[]]",
1256
- "# $!.name-missing “$:Frame.0.unsupported-figure”;",
1251
+ "; [[], “a”] * [[]]",
1252
+ "# $!.star-domain *",
1253
+ "; (0 - 5) * [[]]",
1254
+ "# $!.star-domain *",
1257
1255
  "; gap ([], [[], []])",
1258
- "# $!.name-missing “$:Frame.0.unsupported-figure”;",
1256
+ "# 1",
1259
1257
  "```",
1260
- "Properties and declared parents never decide the domain or an observation.",
1261
- "Inlay preserves metadata on rebuilt nonterminal ancestors and leaves its host",
1258
+ "Properties and declared parents never decide the observer domain or an observation.",
1259
+ "Star preserves metadata on rebuilt nonterminal ancestors and leaves its host",
1262
1260
  "unchanged.",
1263
1261
  "```",
1264
1262
  "; [(gap [.k 1; [[], []]]) = 2, [.k 1; [], [[], []]].### = -1]",
1265
1263
  "# [<>, <>]",
1266
- "; (inlay [.k 1; [], [.j 2; []]] [[]]) = [.k 1; [[]], [.j 2; [[]]]]",
1264
+ "; ([.k 1; [], [.j 2; []]] * [[]]) = [.k 1; [[]], [.j 2; [[]]]]",
1267
1265
  "# <>",
1268
- "; .p [.k 1; []]; .q (inlay p [[]]);",
1266
+ "; .p [.k 1; []]; .q (p * [[]]);",
1269
1267
  "; [q = [.k 1; [[]]], p.k, p = [.k 1; []]]",
1270
1268
  "# [<>, 1, <>]",
1271
1269
  "```",
1272
- "Inlay preserves nesting and empty replacements; native repetition constructs a",
1270
+ "Star preserves nesting and empty replacements; native repetition constructs a",
1273
1271
  "flat product. Both have the same terminal count on Figures.",
1274
1272
  "```",
1275
- "; [(inlay [] [[], []]) = [[], []], (inlay [[]] [[], []]) = [[[], []]]]",
1273
+ "; [([] * [[], []]) = [[], []], ([[]] * [[], []]) = [[[], []]]]",
1276
1274
  "# [<>, <>]",
1277
- "; [(inlay [[], []] []) = [[], []], (inlay [[]] []) = [[]]]",
1275
+ "; [([[], []] * []) = [[], []], ([[]] * []) = [[]]]",
1278
1276
  "# [<>, <>]",
1279
- "; (inlay [[], [], [[], []]] “x”) = [“x”, “x”, [“x”, “x”]]",
1277
+ "; ([[], [], [[], []]] * “x”) = [“x”, “x”, [“x”, “x”]]",
1280
1278
  "# <>",
1281
- "; .y [[], [], []]; .host [[], [[], []]]; .r (inlay host y);",
1279
+ "; .y [[], [], []]; .host [[], [[], []]]; .r (host * y);",
1282
1280
  "; [((r .0) === y), (((r .1) .0) === y), (((r .1) .1) === y), r === host]",
1283
1281
  "# [<>, <>, <>, ()]",
1284
- "; [(inlay [[], []] y).##, ([[], []].## [y]).##]",
1282
+ "; [([[], []] * y).##, ([[], []].## [y]).##]",
1285
1283
  "# [6, 6]",
1286
- "; [([[[], []]].## [[[]]]) = [[[]], [[]]], (inlay [[[], []]] [[]]) = [[[[]], [[]]]]]",
1284
+ "; [([[[], []]].## [[[]]]) = [[[]], [[]]], ([[[], []]] * [[]]) = [[[[]], [[]]]]]",
1287
1285
  "# [<>, <>]",
1288
1286
  "```",
1289
1287
  "Withness uses identity, and its answer is the native boolean.",
@@ -1296,7 +1294,7 @@ export const HC_SOURCES = new Map([
1296
1294
  "```",
1297
1295
  "Native `.###` folds the immediate elements' terminal counts with alternating",
1298
1296
  "signs, one sign per element, and answers a FrameInt even when it is 0 or",
1299
- "positive. Anything that is not a Figure answers nil.",
1297
+ "positive. Mixed arrays and evaluated groups use the same rule.",
1300
1298
  "```",
1301
1299
  "; [[].###, [[]].###, [[], []].###, [[], [[], []]].###, [[[], []], []].###]",
1302
1300
  "# [0, 1, 0, -1, 1]",
@@ -1307,7 +1305,20 @@ export const HC_SOURCES = new Map([
1307
1305
  "; [[[], [[]]], [[[], []], []], [[[[], [], []]]]].###",
1308
1306
  "# 2",
1309
1307
  "; [[1, []].###, [[], “ab”].###, [[], ([], [])].###, 5.###]",
1310
- "# [(), (), (), ()]",
1308
+ "# [0, -1, -1, ()]",
1309
+ "```",
1310
+ "Native Size also measures mixed values, independently of structural Star.",
1311
+ "Numeric magnitude truncates exactly; text length uses native Unicode code-point iteration,",
1312
+ "blob width uses bits, and schemas count declared alternatives.",
1313
+ "```",
1314
+ "; [(7.9).##, (-7.9).##, (-3).##, (0.9).##, 0.##, (-7 / 2).##]",
1315
+ "# [7, 7, 3, 0, 0, 3]",
1316
+ "; [“”.##, “hello”.##, “é😀”.##, 0x00ff.##]",
1317
+ "# [0, 5, 2, 16]",
1318
+ "; [(1).<>.##, <2, 3, 5>.##, <2, 2, [3, 5]>.##, <.a, .b>.##, <>.##]",
1319
+ "# [1, 3, 3, 1, 1]",
1320
+ "; [[5, “hello”].##, [5, “hello”].###, (5, 3).###, [5, 3, 2, 7].###]",
1321
+ "# [10, 0, 2, -3]",
1311
1322
  "```",
1312
1323
  "Gap is `|x.###|` and Spin is `x.### / N`, including shared branches at every",
1313
1324
  "occurrence. Reversing two unequal branches reverses Spin's sign.",
@@ -1324,9 +1335,21 @@ export const HC_SOURCES = new Map([
1324
1335
  "; [z.###, (gap z) = (0 - z.###), (spin z 4) = (z.### / 4)]",
1325
1336
  "# [-3, <>, <>]",
1326
1337
  "; spin [[[], []]] 2.5",
1327
- "# $!.type-error .n <~~1> 2.5",
1338
+ "# $!.type-error .n <(1).<>> 2.5",
1328
1339
  "; spin [[[], []]] 0",
1329
1340
  "# $!.division-by-zero /",
1341
+ "",
1342
+ "```",
1343
+ "Star uses native `*` dispatch; numeric pairs keep arithmetic.",
1344
+ "```",
1345
+ "; [2 * 3, 2 * [[], []], [[], []] * 3, [] * [[], []]]",
1346
+ "# [6, [[[], []], [[], []]], [3, 3], [[], []]]",
1347
+ "; [(2 * [[], [], []]).##, ([[], []] * 3).##, (0 * [[]]).##]",
1348
+ "# [6, 6, 0]",
1349
+ "; [[], [[], []]] * [[]]",
1350
+ "# [[[]], [[[]], [[]]]]",
1351
+ "; [.tag 1;] * [[]]",
1352
+ "# $!.star-metadata *",
1330
1353
  "```",
1331
1354
  "Importing skips the examples and ends on a native true value.",
1332
1355
  "```",
@@ -1491,6 +1514,60 @@ export const HC_SOURCES = new Map([
1491
1514
  "",
1492
1515
  ].join("\n"),
1493
1516
  ],
1517
+ [
1518
+ "hc/membership.hc",
1519
+ [
1520
+ "#!/usr/bin/env hc",
1521
+ "```",
1522
+ "On ordinary element hosts, immediate membership follows the equality ladder: ~ uses =, ~~ uses ==,",
1523
+ "and ~~~ uses ===. The host is on the right. No descendant search or metadata.",
1524
+ "On schema/runtime matcher hosts, ~ retains rich matcher acceptance.",
1525
+ "```",
1526
+ "; [] ~ [[]]",
1527
+ "# <>",
1528
+ "; [] ~~ [[]]",
1529
+ "# <>",
1530
+ "; [] ~~~ [[]]",
1531
+ "# ()",
1532
+ "; 2 ~ [5 - 3]",
1533
+ "# <>",
1534
+ "; 2 ~~ [5 - 3]",
1535
+ "# ()",
1536
+ "; [] ~ [[[]]]",
1537
+ "# ()",
1538
+ "; 1 ~ [.property 1;]",
1539
+ "# ()",
1540
+ "```",
1541
+ "Fano incidence uses shared point objects. Equal form alone is not incidence.",
1542
+ "```",
1543
+ ".point [];",
1544
+ ".other [];",
1545
+ ".line [point];",
1546
+ "; [other ~ line, other ~~ line, other ~~~ line, point ~~~ line]",
1547
+ "# [<>, <>, (), <>]",
1548
+ "; point ~~~ line",
1549
+ "# <>",
1550
+ "; other ~~~ line",
1551
+ "# ()",
1552
+ "```",
1553
+ "Runtime types use .<>; declared binding schemas use .<^>.",
1554
+ "Schema matching with ~ retains its nested contract.",
1555
+ "```",
1556
+ "; “Q” ~ “”.<>",
1557
+ "# <>",
1558
+ "; “Q” ~ 1.<>",
1559
+ "# ()",
1560
+ "; “”.<> “Q”",
1561
+ "# “Q”",
1562
+ "; {.f {missing}; “x” ~ f.<>} ()",
1563
+ "# ()",
1564
+ "; {.x <1, 2> 1; x.<^>} ()",
1565
+ "# <1, 2>",
1566
+ "; 0b101 ~ <3@Bit>",
1567
+ "# <>",
1568
+ "",
1569
+ ].join("\n"),
1570
+ ],
1494
1571
  [
1495
1572
  "hc/numerics.hc",
1496
1573
  [
@@ -1602,7 +1679,7 @@ export const HC_SOURCES = new Map([
1602
1679
  "; [3 xs, xs]",
1603
1680
  "# [[1, 2, 1, 2, 1, 2], [1, 2]]",
1604
1681
  "; [(1 xs) = xs, (1 xs) === xs, ((3 [xs]) .2) === xs, (2 [[1, 2]]).##]",
1605
- "# [<>, (), <>, 4]",
1682
+ "# [<>, (), <>, 6]",
1606
1683
  "```",
1607
1684
  "Cross-rung promotion and integer-only modulo",
1608
1685
  "```",
@@ -1701,7 +1778,7 @@ export const HC_SOURCES = new Map([
1701
1778
  "# -2",
1702
1779
  "```",
1703
1780
  "Comparison and `=` compare values across rungs, so a count and a FrameInt of the",
1704
- "same value are `=`. `==`, `===` and `~~` compare exact types, so the two are",
1781
+ "same value are `=`. `==`, `===` and runtime types from `.<>` compare exact types, so the two are",
1705
1782
  "not `==`, just as `2` and `2.0` are not",
1706
1783
  "```",
1707
1784
  "; 2 = (5 - 3)",
@@ -1716,10 +1793,10 @@ export const HC_SOURCES = new Map([
1716
1793
  "# ()",
1717
1794
  "; 2 == 2.0",
1718
1795
  "# ()",
1719
- "; ~~2 (5 - 3)",
1720
- "# $!.type-error ~~2 2",
1721
- "; ~~(5 - 3) 2",
1722
- "# $!.type-error ~~2 2",
1796
+ "; (2).<> (5 - 3)",
1797
+ "# $!.type-error (2).<> 2",
1798
+ "; (5 - 3).<> 2",
1799
+ "# $!.type-error (2).<> 2",
1723
1800
  "; (0 - 1).< 0",
1724
1801
  "# <>",
1725
1802
  "; 2.<= (5 - 3)",
@@ -1727,15 +1804,15 @@ export const HC_SOURCES = new Map([
1727
1804
  "; 2.< 2.5",
1728
1805
  "# <>",
1729
1806
  "```",
1730
- "Within one rung, `==` and `~~` hold as they always have",
1807
+ "Within one rung, `==` and type application hold as they always have",
1731
1808
  "```",
1732
1809
  "; 2 == (1 + 1)",
1733
1810
  "# <>",
1734
1811
  "; (5 - 3) == (4 - 2)",
1735
1812
  "# <>",
1736
- "; ~~2 3",
1813
+ "; (2).<> 3",
1737
1814
  "# 3",
1738
- "; ~~(0 - 1) (0 - 5)",
1815
+ "; (0 - 1).<> (0 - 5)",
1739
1816
  "# -5",
1740
1817
  "",
1741
1818
  ].join("\n"),
@@ -2004,9 +2081,9 @@ export const HC_SOURCES = new Map([
2004
2081
  "# <>",
2005
2082
  "; 2 ~ ()",
2006
2083
  "# ()",
2007
- "; “Q” ~ ~~“”",
2084
+ "; “Q” ~ (“”).<>",
2008
2085
  "# <>",
2009
- "; “Q” ~ ~~1",
2086
+ "; “Q” ~ (1).<>",
2010
2087
  "# ()",
2011
2088
  "## Closure signatures apply defaults, require bare fields, and allow extras",
2012
2089
  "; .join-name (.first “Jane”, .last) ^ {last “, ” first};",
@@ -3136,12 +3213,12 @@ export const HC_SOURCES = new Map([
3136
3213
  "",
3137
3214
  "#### Type Values",
3138
3215
  "",
3139
- "The simplest way to construct a type is to use the `~~` operator to extract the type",
3216
+ "The simplest way to construct a type is to use the `.<>` accessor to extract the runtime type",
3140
3217
  "of a known object:",
3141
3218
  "```",
3142
- "; “Q” ~ ~~“”",
3219
+ "; “Q” ~ (“”).<>",
3143
3220
  "# <>",
3144
- "; “Q” ~ ~~1",
3221
+ "; “Q” ~ (1).<>",
3145
3222
  "# ()",
3146
3223
  "```",
3147
3224
  "### Content",
@@ -5,6 +5,8 @@ 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 { FrameCount } from "./frame-count.js";
9
+ import { FrameNumeric, REPETITION_LIMIT } from "./frame-numeric.js";
8
10
  import { FrameHandle } from "./frame-handle.js";
9
11
  import { FrameList } from "./frame-list.js";
10
12
  import { FrameNote } from "./frame-note.js";
@@ -13,6 +15,79 @@ export class FrameArray extends FrameList {
13
15
  constructor(data, meta = NilContext) {
14
16
  super(data, meta);
15
17
  }
18
+ /** Count leaves use the same Star rule at the root and inside an array. */
19
+ static starCount(count, replacement) {
20
+ const right = replacement.referent();
21
+ if (right instanceof FrameNumeric)
22
+ return count.multiply(right);
23
+ const refusal = FrameArray.starCountRefusal(count, replacement);
24
+ if (refusal)
25
+ return refusal;
26
+ if (count.data === 0n)
27
+ return count;
28
+ return new FrameArray(Array(Number(count.data)).fill(replacement));
29
+ }
30
+ /** Validate expansion before any ancestor is rebuilt or count is expanded. */
31
+ static starCountRefusal(count, replacement) {
32
+ if (replacement.referent() instanceof FrameNumeric)
33
+ return undefined;
34
+ if (count.meta_pairs().length || count.hasDeclaredParent()) {
35
+ return Frame.error("$!.star-metadata *");
36
+ }
37
+ if (count.data > REPETITION_LIMIT) {
38
+ return Frame.error(`$!.repetition-limit ${REPETITION_LIMIT}`);
39
+ }
40
+ return undefined;
41
+ }
42
+ /**
43
+ * Star: replace empty-array terminals and compose count leaves,
44
+ * sharing the replacement.
45
+ * Copy the same native metadata and declaration echoes as ordinary array
46
+ * reconstruction. A decorated terminal cannot be replaced without loss.
47
+ * Validate before rebuilding; neither operand is evaluated or mutated here.
48
+ */
49
+ star(replacement) {
50
+ const path = new Set();
51
+ const validate = (node) => {
52
+ const value = node.referent();
53
+ if (value instanceof FrameCount) {
54
+ return FrameArray.starCountRefusal(value, replacement);
55
+ }
56
+ if (!(value instanceof FrameArray) || path.has(value)) {
57
+ return Frame.error("$!.star-domain *");
58
+ }
59
+ const elements = value.elements();
60
+ if (!elements.length &&
61
+ (value.asArray().length || value.meta_pairs().length ||
62
+ value.hasDeclaredParent())) {
63
+ return Frame.error("$!.star-metadata *");
64
+ }
65
+ path.add(value);
66
+ for (const element of elements) {
67
+ const error = validate(element);
68
+ if (error)
69
+ return error;
70
+ }
71
+ path.delete(value);
72
+ return undefined;
73
+ };
74
+ const error = validate(this);
75
+ if (error)
76
+ return error;
77
+ const go = (node) => {
78
+ if (node instanceof FrameCount) {
79
+ return FrameArray.starCount(node, replacement);
80
+ }
81
+ if (!node.elements().length)
82
+ return replacement;
83
+ const result = node.copy();
84
+ result.data = node.itemsFor(result, (item) => node.repeatsTerm(item)
85
+ ? go(item.walked().referent())
86
+ : item);
87
+ return result;
88
+ };
89
+ return go(this);
90
+ }
16
91
  string_open() {
17
92
  return FrameArray.BEGIN_ARRAY;
18
93
  }
@@ -63,10 +138,10 @@ export class FrameArray extends FrameList {
63
138
  return true;
64
139
  }
65
140
  /**
66
- * Every array is a Figure node, read through its elements; its properties
67
- * and declared parent are ignored (010.04).
141
+ * An evaluated array exposes ordered data for residual; properties and
142
+ * declared parents are excluded.
68
143
  */
69
- isFigureNode() {
144
+ supportsResidual() {
70
145
  return true;
71
146
  }
72
147
  /**
@@ -71,6 +71,9 @@ export class FrameBlob extends FrameAtom {
71
71
  const digits = "0".repeat(pad) + dataString;
72
72
  return this.string_prefix() + digits + this.string_suffix();
73
73
  }
74
+ nativeSize() {
75
+ return this.n_bits;
76
+ }
74
77
  /** The exact rendered width of this blob, including leading zero bits. */
75
78
  bitLength() {
76
79
  return Number(this.n_bits);
@@ -91,6 +91,9 @@ export class FrameBytes extends FrameAtom {
91
91
  this.data = new Uint8Array(values);
92
92
  this.length = values.length;
93
93
  }
94
+ nativeSize() {
95
+ return BigInt(this.data.length);
96
+ }
94
97
  string_prefix() {
95
98
  return FrameBytes.BYTES_BEGIN;
96
99
  }
@@ -1,5 +1,6 @@
1
1
  import { completeAtEnd, includeOrReserve } from "./atom-syntax.js";
2
2
  import { NilContext } from "./context.js";
3
+ import { Frame } from "./frame.js";
3
4
  import { FrameInt } from "./frame-int.js";
4
5
  import { NUMERIC_RANK, } from "./frame-numeric.js";
5
6
  /**
@@ -74,3 +75,4 @@ Object.defineProperty(FrameCount, "SYNTAX", {
74
75
  fromSource: (source) => FrameCount.for(source),
75
76
  }
76
77
  });
78
+ Frame.count = (value) => new FrameCount(value);
@@ -81,6 +81,9 @@ export class FrameExpr extends FrameList {
81
81
  elements() {
82
82
  return atomsOf(this.data, sitesAround(this.data));
83
83
  }
84
+ sizeElements() {
85
+ return sizeAtomsOf(this.data);
86
+ }
84
87
  /** A parsed expression of one atom is that atom; anything else is itself. */
85
88
  walked() {
86
89
  if (!isPlainExpr(this))
@@ -112,6 +115,13 @@ export class FrameExpr extends FrameList {
112
115
  const value = item.in(resumedScope(item, scope));
113
116
  if (value.is.error === true)
114
117
  return value;
118
+ // An explicit nil receiver still has a Size. The initial nil accumulator
119
+ // is not a receiver, so a leading .## remains an address (#411).
120
+ if (index > 0 && sum.is.void && value instanceof FrameSymbol &&
121
+ value.is.address &&
122
+ [Frame.kLEAVES, Frame.kRESIDUAL].includes(value.spelling())) {
123
+ return value.called_by(sum);
124
+ }
115
125
  if (index > 0 && value.is.operator === true) {
116
126
  return value.called_by(sum, Frame.nil).atSite(scope);
117
127
  }
@@ -120,7 +130,7 @@ export class FrameExpr extends FrameList {
120
130
  }
121
131
  schemaRetrieval(scope) {
122
132
  if (this.data.length !== 2 || !(this.data[0] instanceof FrameSymbol) ||
123
- !(this.data[1] instanceof FrameName) || this.data[1].source !== "<>")
133
+ !(this.data[1] instanceof FrameName) || this.data[1].source !== "<^>")
124
134
  return undefined;
125
135
  return this.data[0].bindingSchema(resumedScope(this.data[0], scope));
126
136
  }
@@ -292,6 +302,53 @@ export function atomsOf(terms, sites = new Map(), resume) {
292
302
  }
293
303
  return atoms;
294
304
  }
305
+ /**
306
+ * The same represented words as a syntax walk, without recording scope sites or
307
+ * binding names. Compound atoms stay whole; only trivial wrappers are unwrapped.
308
+ * A malformed cyclic wrapper is refused before it can recurse forever.
309
+ */
310
+ export function sizeAtomsOf(terms) {
311
+ const atoms = [];
312
+ let cyclic = false;
313
+ const walkAtom = (term, path = new Set()) => {
314
+ if (isPlainExpr(term) && term.size() === 1) {
315
+ if (path.has(term)) {
316
+ cyclic = true;
317
+ return;
318
+ }
319
+ path.add(term);
320
+ walkAtom(term.asArray()[0], path);
321
+ path.delete(term);
322
+ }
323
+ else if (term instanceof FrameName) {
324
+ atoms.push(FrameWord.address(term.source));
325
+ }
326
+ else if (term instanceof FrameSymbol) {
327
+ atoms.push(FrameWord.word(term.spelling()));
328
+ }
329
+ else {
330
+ atoms.push(term);
331
+ }
332
+ };
333
+ let previous;
334
+ for (const term of terms) {
335
+ if (isPlainExpr(term) && previous && isPlainExpr(previous) &&
336
+ !previous.is.statement) {
337
+ atoms.push(FrameWord.word(","));
338
+ }
339
+ if (isPlainExpr(term)) {
340
+ for (const inner of term.asArray())
341
+ walkAtom(inner);
342
+ if (term.is.statement)
343
+ atoms.push(FrameWord.word(";"));
344
+ }
345
+ else {
346
+ walkAtom(term);
347
+ }
348
+ previous = term;
349
+ }
350
+ return cyclic ? Frame.error("$!.cyclic-aggregate .##") : atoms;
351
+ }
295
352
  /**
296
353
  * Whether a body's terms are one comma expression: two or more parsed terms
297
354
  * the source separated with `,`, rather than bare atoms or statements.
@@ -371,8 +428,8 @@ export class FrameScoped extends Frame {
371
428
  live() {
372
429
  return isClosure(this.term) ? this.term.in(this.scope) : this.term;
373
430
  }
374
- referent() {
375
- return this.term.referent();
431
+ referent(path = new Set()) {
432
+ return this.referenceThrough(this.term, path);
376
433
  }
377
434
  elements() {
378
435
  const terms = this.term.asArray();
@@ -385,7 +442,10 @@ export class FrameScoped extends Frame {
385
442
  return this;
386
443
  }
387
444
  sizeFor(key) {
388
- return this.term.sizeFor(key);
445
+ return this.referent().sizeFor(key);
446
+ }
447
+ nativeSize(path) {
448
+ return this.referent().nativeSize(path);
389
449
  }
390
450
  /** Sizes as its term does, `.#`, `.##` and `.###`; anything else is applied. */
391
451
  call(argument, parameter = Frame.nil) {
@@ -429,6 +489,7 @@ function resumedScope(term, scope) {
429
489
  }
430
490
  /** A source aggregate walks as a body does. */
431
491
  FrameList.walkSource = (terms) => atomsOf(terms, sitesAround(terms));
492
+ FrameList.sizeSource = sizeAtomsOf;
432
493
  /** The declarations around a closure body, as far as a walk has seen them. */
433
494
  export function sitesAround(body) {
434
495
  return (body[0] && enclosingSites.get(body[0])) ?? new Map();
@@ -10,6 +10,9 @@ export class FrameGroup extends FrameList {
10
10
  constructor(data, meta = NilContext) {
11
11
  super(data, meta);
12
12
  }
13
+ supportsResidual() {
14
+ return true;
15
+ }
13
16
  /**
14
17
  * The scope this group's terms are evaluated in. `target` is the layer they
15
18
  * read the group's properties from and, for a group written in source, the
@@ -103,8 +103,14 @@ export class FrameHandle extends Frame {
103
103
  return this;
104
104
  }
105
105
  /** A handle is transparent to equality: it compares as its target. */
106
- referent() {
107
- return this.target.referent();
106
+ referent(path = new Set()) {
107
+ return this.referenceThrough(this.target, path);
108
+ }
109
+ sizeFor(key) {
110
+ return this.referent().sizeFor(key);
111
+ }
112
+ nativeSize(path) {
113
+ return this.referent().nativeSize(path);
108
114
  }
109
115
  equals(other) {
110
116
  return this.target.equals(other);
@@ -1,4 +1,5 @@
1
1
  import { Frame } from "./frame.js";
2
+ import { FrameType } from "./frame-type.js";
2
3
  import { atomsOf, FrameExpr, noteEnclosing, sitesAround, } from "./frame-expr.js";
3
4
  import { FrameGroup } from "./frame-group.js";
4
5
  import { FrameSymbol } from "./frame-symbol.js";
@@ -92,12 +93,11 @@ export class FrameLazy extends FrameExpr {
92
93
  : undefined;
93
94
  }
94
95
  /**
95
- * A closure walks as the atoms of its body (#429), so `.#` counts them and
96
- * `.##` the terminals below them, as for any aggregate (#411); an empty
97
- * body is one terminal. A closure is not a Figure, so `.###` is nil
98
- * (010.04). The operator
99
- * reaches a closure as its argument, where a body would otherwise run, so
100
- * it is answered here before the body is.
96
+ * `.#` counts the body's represented words (#429). `.##` sums their native
97
+ * Sizes without execution or evaluation-site registration; an empty body
98
+ * retains Size 1. A closure's words are executable syntax, so it has no
99
+ * ordered data plane for `.###` and answers nil (010.08). The operator
100
+ * reaches a closure as its argument and is answered before its body runs.
101
101
  */
102
102
  sizeOperator(argument) {
103
103
  if (argument instanceof FrameSymbol && argument.is.address === true &&
@@ -124,6 +124,9 @@ export class FrameLazy extends FrameExpr {
124
124
  }
125
125
  /** Evaluates this closure with optional bound receiver capability. */
126
126
  call(argument, parameter = Frame.nil, receiverState) {
127
+ if (argument instanceof FrameSymbol && argument.is.address === true &&
128
+ argument.spelling() === "<>")
129
+ return FrameType.of(this);
127
130
  const size = this.sizeOperator(argument);
128
131
  if (size)
129
132
  return size;
@@ -125,6 +125,12 @@ export class FrameList extends Frame {
125
125
  }
126
126
  return this.data.filter((item) => this.isElement(item)).map((item) => item.walked());
127
127
  }
128
+ /** Quantity walks must not record evaluation sites or bind source words. */
129
+ sizeElements() {
130
+ return this.is.source === true && FrameList.sizeSource
131
+ ? FrameList.sizeSource(this.data)
132
+ : this.countedElements();
133
+ }
128
134
  /**
129
135
  * The elements a size operator counts: `elements()`, unless a kind can
130
136
  * count them more cheaply, as a closure does without its scope (a17).
@@ -136,120 +142,57 @@ export class FrameList extends Frame {
136
142
  isElement(term) {
137
143
  return term.is.statement !== true && !this.holdsAsProperty(term);
138
144
  }
139
- /**
140
- * `.#` counts this aggregate's elements (#411) and `.##` the terminals of
141
- * its structure (issue occurrence/figure 010.02), so neither counts a
142
- * property. `.###` is a Figure's signed residual (010.04). Every aggregate
143
- * is a list, so each one answers here rather than in its own class.
144
- */
145
+ /** Immediate count is unchanged; Size and residual share native child sizes. */
145
146
  sizeFor(key) {
146
147
  if (key === Frame.kCOUNT) {
147
148
  return new FrameCount(BigInt(this.countedElements().length));
148
149
  }
149
- if (key === Frame.kRESIDUAL)
150
- return this.residual();
151
- const terminals = this.terminalCount(new Set());
152
- return terminals === undefined
153
- ? Frame.error(`$!.cyclic-aggregate .${key}`)
154
- : new FrameCount(terminals);
150
+ return key === Frame.kRESIDUAL ? this.residual() : super.sizeFor(key);
155
151
  }
156
- /**
157
- * The terminals of this aggregate's structure, the nodes with no elements
158
- * below them. An aggregate with no elements is itself one terminal, at the
159
- * root or nested, so `[]` counts 1 and `.##` never answers 0 for an
160
- * aggregate. A nonempty aggregate counts its elements' terminals: each
161
- * element that is not an aggregate is one terminal, and each aggregate
162
- * element counts its own, at any depth. Properties are not elements, so an
163
- * aggregate holding only properties is one terminal too.
164
- *
165
- * On finite, property-free nested arrays this is Figure terminal count:
166
- * `[[], [[], []]].##` is 3. Through v0.32.1 an empty aggregate counted 0,
167
- * so `.##` counted only the non-aggregate leaves (#411).
168
- *
169
- * `path` holds only the aggregates from the root down to this one, so a
170
- * branch reached twice counts twice, and one that contains itself answers
171
- * undefined.
172
- */
173
- terminalCount(path) {
152
+ /** Empty aggregates retain one terminal; shared descendants count per occurrence. */
153
+ nativeSize(path) {
174
154
  if (path.has(this))
175
- return undefined;
176
- const elements = this.countedElements();
177
- if (elements.length === 0)
178
- return 1n;
155
+ return Frame.error("$!.cyclic-aggregate .##");
179
156
  path.add(this);
180
- let terminals = 0n;
181
- for (const element of elements) {
182
- const value = element.referent();
183
- const below = value instanceof FrameList ? value.terminalCount(path) : 1n;
184
- if (below === undefined)
185
- return undefined;
186
- terminals += below;
157
+ try {
158
+ const elements = this.sizeElements();
159
+ if (elements instanceof Frame)
160
+ return elements;
161
+ if (elements.length === 0)
162
+ return 1n;
163
+ let size = 0n;
164
+ for (const element of elements) {
165
+ const below = element.referent().nativeSize(path);
166
+ if (typeof below !== "bigint")
167
+ return below;
168
+ size += below;
169
+ }
170
+ return size;
171
+ }
172
+ finally {
173
+ path.delete(this);
187
174
  }
188
- path.delete(this);
189
- return terminals;
190
175
  }
191
- /**
192
- * Whether this aggregate can be a node of a Figure, a finite nested array
193
- * (010.04). Only an array can, so groups, schemas and closures answer false
194
- * here. Properties are not elements, so they never decide it.
195
- */
196
- isFigureNode() {
176
+ /** Only concrete ordered data hosts opt in, never executable/matcher syntax. */
177
+ supportsResidual() {
197
178
  return false;
198
179
  }
199
- /**
200
- * `.###`, the signed alternating sum of the terminal counts of a Figure's
201
- * immediate elements, `T(x₁) − T(x₂) + T(x₃) − …`, always a FrameInt and 0
202
- * for `[]` (issue occurrence/figure 010.04). A terminal is an empty frame,
203
- * so on a Figure `T` is `.##`. Each element is folded with one sign; the
204
- * signs do not alternate over the terminals below it.
205
- *
206
- * A Figure is read through its elements only, so properties and a declared
207
- * parent are ignored at every level, as `.#` and `.##` ignore them. Anything
208
- * else is not a Figure and answers nil, as `.#` does for a non-aggregate:
209
- * an atom, a string, a group, a schema or a closure anywhere in the
210
- * structure, or an aggregate that contains itself.
211
- */
180
+ /** Alternate over immediate positions, using each child's complete Size. */
212
181
  residual() {
213
- if (!this.isFigureNode())
182
+ if (!this.supportsResidual() || this.is.source === true)
214
183
  return Frame.nil;
215
184
  const path = new Set([this]);
216
185
  let signed = 0n;
217
186
  let positive = true;
218
187
  for (const element of this.countedElements()) {
219
- const terminals = FrameList.figureTerminals(element.referent(), path);
220
- if (terminals === undefined)
188
+ const size = element.referent().nativeSize(path);
189
+ if (typeof size !== "bigint")
221
190
  return Frame.nil;
222
- signed += positive ? terminals : -terminals;
191
+ signed += positive ? size : -size;
223
192
  positive = !positive;
224
193
  }
225
194
  return new FrameInt(signed);
226
195
  }
227
- /**
228
- * The terminal count of `value` as a Figure: 1 for an empty frame, else the
229
- * sum over its elements. Answers undefined when any node is not a Figure
230
- * node or contains itself. `path` holds the nodes from the root down, as
231
- * for `terminalCount`, so a shared branch counts at every occurrence.
232
- */
233
- static figureTerminals(value, path) {
234
- if (!(value instanceof FrameList) || !value.isFigureNode()) {
235
- return undefined;
236
- }
237
- if (path.has(value))
238
- return undefined;
239
- const elements = value.countedElements();
240
- if (elements.length === 0)
241
- return 1n;
242
- path.add(value);
243
- let terminals = 0n;
244
- for (const element of elements) {
245
- const below = FrameList.figureTerminals(element.referent(), path);
246
- if (below === undefined)
247
- return undefined;
248
- terminals += below;
249
- }
250
- path.delete(value);
251
- return terminals;
252
- }
253
196
  /**
254
197
  * `n x` for an aggregate concatenates (v0.22.0). The answer is a fresh
255
198
  * aggregate of x's kind holding the terms x keeps once, its properties and
@@ -20,7 +20,10 @@ const recognizeName = (symbol, source = "") => {
20
20
  if (source.startsWith(".")) {
21
21
  return { disposition: ScanDisposition.CompleteRedispatch };
22
22
  }
23
- if (source.endsWith("^")) {
23
+ // Reserve observation spellings and leave a following schema closer alone.
24
+ // The caret inside .<^> is not an effect suffix.
25
+ if (source === "<>" || source === "<^>" ||
26
+ (source.endsWith("^") && source !== "<^")) {
24
27
  return { disposition: ScanDisposition.CompleteRedispatch };
25
28
  }
26
29
  // `#` begins a comment except where it spells a size operator, `.#`, `.##`
@@ -81,6 +81,21 @@ export function projectBigIntRatio(numerator, denominator) {
81
81
  }
82
82
  /** Shared rank-based numeric dispatch and unary/apply behavior. */
83
83
  export class FrameNumeric extends FrameAtom {
84
+ nativeSize(path) {
85
+ // Dimensional and dotted values have no implicit unit or magnitude.
86
+ if (this.rank === null)
87
+ return super.nativeSize(path);
88
+ const ratio = this.exactRatio();
89
+ if (ratio) {
90
+ const [numerator, denominator] = ratio;
91
+ const quotient = numerator / denominator;
92
+ return quotient < 0n ? -quotient : quotient;
93
+ }
94
+ const value = this.valueOf();
95
+ return typeof value === "number" && Number.isFinite(value)
96
+ ? BigInt(Math.trunc(Math.abs(value)))
97
+ : Frame.error("$!.nonquantifiable-size .##");
98
+ }
84
99
  add(right) {
85
100
  return this.join(right, "+", (left, joinedRight) => left.addSame(joinedRight));
86
101
  }
@@ -62,6 +62,14 @@ export class FrameSchema extends FrameList {
62
62
  }
63
63
  return this;
64
64
  }
65
+ nativeSize() {
66
+ // Empty enumeration means the total type, not an empty finite domain.
67
+ // Inspect the installed matcher only; never traverse/compile candidates.
68
+ return this.matcher instanceof EnumerationSchemaMatcher &&
69
+ this.data.length > 0
70
+ ? BigInt(this.data.length)
71
+ : 1n;
72
+ }
65
73
  match(value, origin = Frame.nil) {
66
74
  return this.matcher.match(this, value, origin);
67
75
  }
@@ -280,6 +280,9 @@ export class FrameSymbol extends FrameAtom {
280
280
  });
281
281
  }
282
282
  called_by(context) {
283
+ if (this.is.address === true && this.data === "<>") {
284
+ return FrameType.of(context);
285
+ }
283
286
  // A size operator answers for the receiver itself rather than looking a
284
287
  // name up, so the scope a value was read from never answers for it (#411).
285
288
  // Only an address is one, since the lexer looks `#` up as the comment.
@@ -441,12 +444,6 @@ export class FrameOperator extends FrameSymbol {
441
444
  bound.receiverState = receiverState;
442
445
  return bound;
443
446
  }
444
- apply(argument, parameter) {
445
- if (this.operator === "~~") {
446
- return FrameType.of(argument);
447
- }
448
- return super.apply(argument, parameter);
449
- }
450
447
  called_by(context) {
451
448
  const value = FrameSymbol.for(this.data).called_by(context);
452
449
  return value instanceof FrameCurry && this.receiverState
@@ -25,6 +25,15 @@ export class FrameText extends FrameAtom {
25
25
  value: data
26
26
  });
27
27
  }
28
+ nativeSize(path) {
29
+ if (!hasCharacterContent(this))
30
+ return super.nativeSize(path);
31
+ // Native string iteration counts a surrogate pair as one Unicode code point.
32
+ let characters = 0n;
33
+ for (const _character of this.characterContent())
34
+ characters += 1n;
35
+ return characters;
36
+ }
28
37
  toData() {
29
38
  return this.data;
30
39
  }
@@ -18,13 +18,14 @@ export class FrameType extends Frame {
18
18
  });
19
19
  }
20
20
  static of(representative) {
21
+ representative = representative.referent();
21
22
  return new FrameType(representative.constructor, representative);
22
23
  }
23
24
  matches(value) {
24
25
  return this.match(value).matched;
25
26
  }
26
27
  match(value) {
27
- return value.constructor === this.FrameClass
28
+ return value.referent().constructor === this.FrameClass
28
29
  ? matchSuccess(value)
29
30
  : matchFailure(Frame.error(`$!.type-error ${this.toString()} ${value.toString()}`));
30
31
  }
@@ -33,7 +34,7 @@ export class FrameType extends Frame {
33
34
  return result.matched ? result.evidence : result.error;
34
35
  }
35
36
  toString() {
36
- return `~~${this.representative.toString()}`;
37
+ return `(${this.representative.toString()}).<>`;
37
38
  }
38
39
  dataString() {
39
40
  return this.toString();
@@ -207,9 +207,25 @@ export class Frame extends MetaFrame {
207
207
  return left.typeEquals(right);
208
208
  }
209
209
  /** The frame a reference reaches. A handle answers its target. */
210
- referent() {
210
+ referent(_path) {
211
211
  return this;
212
212
  }
213
+ /** Reference ancestry is separate from aggregate containment ancestry. */
214
+ referenceThrough(target, path) {
215
+ if (path.has(this)) {
216
+ const refusal = Frame.error("$!.cyclic-reference");
217
+ // This failed traversal is not a stored opaque error atom of Size 1.
218
+ refusal.is.cyclicReference = true;
219
+ return refusal;
220
+ }
221
+ path.add(this);
222
+ try {
223
+ return target.referent(path);
224
+ }
225
+ finally {
226
+ path.delete(this);
227
+ }
228
+ }
213
229
  /**
214
230
  * Whether this is a plain parsed expression: a statement of a body or an
215
231
  * aggregate, or a tight expression nested in one (spec a16). A closure is
@@ -245,12 +261,18 @@ export class Frame extends MetaFrame {
245
261
  }
246
262
  /**
247
263
  * What this frame answers for a size operator, `.#`, `.##` or `.###`
248
- * (#411). Only an aggregate counts and a count is its own size, so anything
249
- * else is nil. `.###` answers only on Figures, nested arrays (issue
250
- * occurrence/figure 010.04).
264
+ * (#411). Size counts represented quantity; opaque atoms count once.
265
+ * Immediate count and signed residual are partial, with kind-specific rules.
251
266
  */
252
- sizeFor(_key) {
253
- return Frame.nil;
267
+ sizeFor(key) {
268
+ if (key !== Frame.kLEAVES)
269
+ return Frame.nil;
270
+ const size = this.nativeSize(new Set());
271
+ return typeof size === "bigint" ? Frame.count(size) : size;
272
+ }
273
+ /** Nonnegative represented quantity; path tracks recursive containment only. */
274
+ nativeSize(_path) {
275
+ return this.is.cyclicReference ? this : 1n;
254
276
  }
255
277
  /**
256
278
  * What integer repetition `n x` answers when this frame, x, has a rule of
@@ -533,6 +555,13 @@ export class Frame extends MetaFrame {
533
555
  }
534
556
  return replaced;
535
557
  }
558
+ static quantityOperator(argument) {
559
+ if (argument.className() !== "FrameSymbol" || !argument.is.address) {
560
+ return undefined;
561
+ }
562
+ const key = argument.spelling();
563
+ return key === Frame.kLEAVES || key === Frame.kRESIDUAL ? key : undefined;
564
+ }
536
565
  /**
537
566
  * Negation is decided by the symbol's name, never by how it prints.
538
567
  *
@@ -650,6 +679,9 @@ Object.defineProperty(Frame, "all", {
650
679
  return "<>";
651
680
  }
652
681
  call(argument) {
682
+ const key = Frame.quantityOperator(argument);
683
+ if (key)
684
+ return this.sizeFor(key);
653
685
  return Frame.isBooleanNegation(argument) ? Frame.nil : this;
654
686
  }
655
687
  })()
@@ -44,7 +44,7 @@ export function closureFromAtoms(atoms, site) {
44
44
  }
45
45
  close(false);
46
46
  // Statements stay statements, as the parser holds them, so a statement's
47
- // own forms, such as `x .<>`, resume as they run.
47
+ // own forms, such as `x .<^>`, resume as they run.
48
48
  const closure = new FrameLazy(statements);
49
49
  if (sequence)
50
50
  closure.is.sequence = true;
@@ -1,6 +1,8 @@
1
1
  // Direct, not ../frames.ts, whose ../ops.ts needs this module loaded first.
2
2
  import { Frame } from "../frames/frame.js";
3
3
  import { FrameNumeric } from "../frames/frame-numeric.js";
4
+ import { FrameArray } from "../frames/frame-array.js";
5
+ import { FrameCount } from "../frames/frame-count.js";
4
6
  const numeric = (source, block, operation) => {
5
7
  return source instanceof FrameNumeric && block instanceof FrameNumeric
6
8
  ? operation(source, block)
@@ -8,7 +10,19 @@ const numeric = (source, block, operation) => {
8
10
  };
9
11
  export const Add = (source, block) => numeric(source, block, (left, right) => left.add(right));
10
12
  export const Subtract = (source, block) => numeric(source, block, (left, right) => left.subtract(right));
11
- export const Multiply = (source, block) => numeric(source, block, (left, right) => left.multiply(right));
13
+ /** Star constructs a frame; numeric pairs retain the existing arithmetic ladder. */
14
+ export const Multiply = (source, block) => {
15
+ const left = source.referent();
16
+ const right = block.referent();
17
+ if (left instanceof FrameNumeric && right instanceof FrameNumeric) {
18
+ return left.multiply(right);
19
+ }
20
+ if (left instanceof FrameArray)
21
+ return left.star(block);
22
+ if (left instanceof FrameCount)
23
+ return FrameArray.starCount(left, block);
24
+ return Frame.error("$!.star-domain *");
25
+ };
12
26
  export const Divide = (source, block) => numeric(source, block, (left, right) => left.divide(right));
13
27
  export const Modulo = (source, block) => numeric(source, block, (left, right) => left.modulo(right));
14
28
  export const Power = (source, block) => numeric(source, block, (left, right) => left.power(right));
@@ -0,0 +1,26 @@
1
+ // Enter the aggregate cycle at FrameLazy, as schema matchers do.
2
+ import "../frames/frame-lazy.js";
3
+ import { Frame } from "../frames/frame.js";
4
+ import { FrameList } from "../frames/frame-list.js";
5
+ import { isFrameMatcher } from "../frames/frame-match.js";
6
+ import { HasType } from "./type-operations.js";
7
+ /** Only aggregates expose immediate elements; scalar iteration is not membership. */
8
+ const member = (candidate, host, same) => {
9
+ const right = host.referent();
10
+ return right instanceof FrameList &&
11
+ right.elements().some((element) => same(candidate, element) === Frame.all)
12
+ ? Frame.all
13
+ : Frame.nil;
14
+ };
15
+ /** `~` preserves rich type/schema matching on matcher hosts. */
16
+ export const Member = (candidate, host) => {
17
+ const right = host.referent();
18
+ if (right === Frame.all || right === Frame.nil || isFrameMatcher(right)) {
19
+ return HasType(candidate.referent(), right);
20
+ }
21
+ return member(candidate, right, (left, element) => left.equals(element));
22
+ };
23
+ /** `~~` compares immediate elements by the existing typed equality. */
24
+ export const TypedMember = (candidate, host) => member(candidate, host, (left, element) => left.typeEquals(element));
25
+ /** `~~~` compares immediate elements by the existing identity rule. */
26
+ export const IdenticalMember = (candidate, host) => member(candidate, host, (left, element) => left.identical(element));
package/esm/lib/ops.js CHANGED
@@ -2,7 +2,8 @@ import { IfElse, IfThen } from "./ops/conditionals.js";
2
2
  import { FrameOps } from "./ops/frame-ops.js";
3
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
- import { BindType, HasType } from "./ops/type-operations.js";
5
+ import { IdenticalMember, Member, TypedMember } from "./ops/membership.js";
6
+ import { BindType } from "./ops/type-operations.js";
6
7
  export { FrameCurry } from "./ops/frame-curry.js";
7
8
  export const Ops = new FrameOps({
8
9
  "&": MapElements,
@@ -27,6 +28,8 @@ export const Ops = new FrameOps({
27
28
  "<": LessThan,
28
29
  "<<": LessThan,
29
30
  "<=": LessThanOrEqual,
30
- "~": HasType,
31
+ "~": Member,
32
+ "~~": TypedMember,
33
+ "~~~": IdenticalMember,
31
34
  "^": BindType,
32
35
  });
@@ -1 +1 @@
1
- export const VERSION = "0.34.0";
1
+ export const VERSION = "0.37.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.34.0",
3
+ "version": "0.37.0",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",