hclang 0.34.0 → 0.36.1
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 +117 -55
- package/esm/lib/frames/frame-array.js +75 -0
- package/esm/lib/frames/frame-expr.js +1 -1
- package/esm/lib/frames/frame-lazy.js +4 -0
- package/esm/lib/frames/frame-list.js +8 -4
- package/esm/lib/frames/frame-name.js +4 -1
- package/esm/lib/frames/frame-symbol.js +3 -6
- package/esm/lib/frames/frame-type.js +3 -2
- package/esm/lib/frames/reread.js +1 -1
- package/esm/lib/ops/math.js +15 -1
- package/esm/lib/ops/membership.js +26 -0
- package/esm/lib/ops.js +5 -2
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -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.
|
|
697
|
-
"
|
|
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
|
-
"#
|
|
705
|
+
"# 8",
|
|
704
706
|
"; (1, [2, 3]) .##",
|
|
705
|
-
"#
|
|
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.
|
|
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,13 +1175,14 @@ 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.
|
|
1177
|
-
"
|
|
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 `.##`
|
|
1181
|
+
"Native `.##` weights nested counts by their Size and other atoms by one;",
|
|
1182
|
+
"native `.###` answers nil on",
|
|
1180
1183
|
"anything that is not a Figure, so this module's traversals stay in the domain.",
|
|
1181
1184
|
"",
|
|
1182
|
-
"Only operations
|
|
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
|
"```",
|
|
@@ -1194,25 +1197,18 @@ export const HC_SOURCES = new Map([
|
|
|
1194
1197
|
"```",
|
|
1195
1198
|
".need {.x _; (pure x) ? {x} : {unsupported-figure}};",
|
|
1196
1199
|
"```",
|
|
1197
|
-
"`
|
|
1198
|
-
"
|
|
1199
|
-
"
|
|
1200
|
-
"
|
|
1201
|
-
"
|
|
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
|
-
"```",
|
|
1200
|
+
"Native Star `x * y` replaces empty-array terminals with y and composes",
|
|
1201
|
+
"FrameCount leaves using the same rule as a root count, including zero.",
|
|
1202
|
+
"Replacements are shared by identity; ancestors preserve native metadata.",
|
|
1203
|
+
"Terminals carrying metadata or statements are refused to avoid losing them.",
|
|
1204
|
+
"Use `*` directly; the Figures module provides no composition wrapper.",
|
|
1205
|
+
"",
|
|
1210
1206
|
"`withness x [f, …]` asks whether every requested frame is an immediate element",
|
|
1211
1207
|
"of x by native identity. It returns a native boolean. No requested frames is true.",
|
|
1212
1208
|
"```",
|
|
1213
1209
|
".withness {.x _; .host x;",
|
|
1214
1210
|
" {.fs _;",
|
|
1215
|
-
" .absent (fs &| {.f _; (
|
|
1211
|
+
" .absent (fs &| {.f _; (f ~~~ host) ? {[]} : {[f]}});",
|
|
1216
1212
|
" absent = []}};",
|
|
1217
1213
|
"```",
|
|
1218
1214
|
"`gap x` is the absolute value of native `x.###`, the alternating sum of its",
|
|
@@ -1229,7 +1225,7 @@ export const HC_SOURCES = new Map([
|
|
|
1229
1225
|
"```",
|
|
1230
1226
|
".spin {.x _; .host x;",
|
|
1231
1227
|
" (pure host) ? {",
|
|
1232
|
-
" {.n
|
|
1228
|
+
" {.n <(1).<>> _;",
|
|
1233
1229
|
" .signed (host.###);",
|
|
1234
1230
|
" (n .< 1) ? {signed / 0} : {signed / n}}} : {",
|
|
1235
1231
|
" {.n _; need host}}};",
|
|
@@ -1250,40 +1246,40 @@ export const HC_SOURCES = new Map([
|
|
|
1250
1246
|
"# [<>, <>, (), <>]",
|
|
1251
1247
|
"; [(need e) = e, (need e) === e]",
|
|
1252
1248
|
"# [<>, <>]",
|
|
1253
|
-
";
|
|
1254
|
-
"# $!.
|
|
1255
|
-
";
|
|
1256
|
-
"# $!.
|
|
1249
|
+
"; [[], “a”] * [[]]",
|
|
1250
|
+
"# $!.star-domain *",
|
|
1251
|
+
"; (0 - 5) * [[]]",
|
|
1252
|
+
"# $!.star-domain *",
|
|
1257
1253
|
"; gap ([], [[], []])",
|
|
1258
1254
|
"# $!.name-missing “$:Frame.0.unsupported-figure”;",
|
|
1259
1255
|
"```",
|
|
1260
|
-
"Properties and declared parents never decide the domain or an observation.",
|
|
1261
|
-
"
|
|
1256
|
+
"Properties and declared parents never decide the observer domain or an observation.",
|
|
1257
|
+
"Star preserves metadata on rebuilt nonterminal ancestors and leaves its host",
|
|
1262
1258
|
"unchanged.",
|
|
1263
1259
|
"```",
|
|
1264
1260
|
"; [(gap [.k 1; [[], []]]) = 2, [.k 1; [], [[], []]].### = -1]",
|
|
1265
1261
|
"# [<>, <>]",
|
|
1266
|
-
"; (
|
|
1262
|
+
"; ([.k 1; [], [.j 2; []]] * [[]]) = [.k 1; [[]], [.j 2; [[]]]]",
|
|
1267
1263
|
"# <>",
|
|
1268
|
-
"; .p [.k 1; []]; .q (
|
|
1264
|
+
"; .p [.k 1; []]; .q (p * [[]]);",
|
|
1269
1265
|
"; [q = [.k 1; [[]]], p.k, p = [.k 1; []]]",
|
|
1270
1266
|
"# [<>, 1, <>]",
|
|
1271
1267
|
"```",
|
|
1272
|
-
"
|
|
1268
|
+
"Star preserves nesting and empty replacements; native repetition constructs a",
|
|
1273
1269
|
"flat product. Both have the same terminal count on Figures.",
|
|
1274
1270
|
"```",
|
|
1275
|
-
"; [(
|
|
1271
|
+
"; [([] * [[], []]) = [[], []], ([[]] * [[], []]) = [[[], []]]]",
|
|
1276
1272
|
"# [<>, <>]",
|
|
1277
|
-
"; [(
|
|
1273
|
+
"; [([[], []] * []) = [[], []], ([[]] * []) = [[]]]",
|
|
1278
1274
|
"# [<>, <>]",
|
|
1279
|
-
"; (
|
|
1275
|
+
"; ([[], [], [[], []]] * “x”) = [“x”, “x”, [“x”, “x”]]",
|
|
1280
1276
|
"# <>",
|
|
1281
|
-
"; .y [[], [], []]; .host [[], [[], []]]; .r (
|
|
1277
|
+
"; .y [[], [], []]; .host [[], [[], []]]; .r (host * y);",
|
|
1282
1278
|
"; [((r .0) === y), (((r .1) .0) === y), (((r .1) .1) === y), r === host]",
|
|
1283
1279
|
"# [<>, <>, <>, ()]",
|
|
1284
|
-
"; [(
|
|
1280
|
+
"; [([[], []] * y).##, ([[], []].## [y]).##]",
|
|
1285
1281
|
"# [6, 6]",
|
|
1286
|
-
"; [([[[], []]].## [[[]]]) = [[[]], [[]]], (
|
|
1282
|
+
"; [([[[], []]].## [[[]]]) = [[[]], [[]]], ([[[], []]] * [[]]) = [[[[]], [[]]]]]",
|
|
1287
1283
|
"# [<>, <>]",
|
|
1288
1284
|
"```",
|
|
1289
1285
|
"Withness uses identity, and its answer is the native boolean.",
|
|
@@ -1324,9 +1320,21 @@ export const HC_SOURCES = new Map([
|
|
|
1324
1320
|
"; [z.###, (gap z) = (0 - z.###), (spin z 4) = (z.### / 4)]",
|
|
1325
1321
|
"# [-3, <>, <>]",
|
|
1326
1322
|
"; spin [[[], []]] 2.5",
|
|
1327
|
-
"# $!.type-error .n
|
|
1323
|
+
"# $!.type-error .n <(1).<>> 2.5",
|
|
1328
1324
|
"; spin [[[], []]] 0",
|
|
1329
1325
|
"# $!.division-by-zero /",
|
|
1326
|
+
"",
|
|
1327
|
+
"```",
|
|
1328
|
+
"Star uses native `*` dispatch; numeric pairs keep arithmetic.",
|
|
1329
|
+
"```",
|
|
1330
|
+
"; [2 * 3, 2 * [[], []], [[], []] * 3, [] * [[], []]]",
|
|
1331
|
+
"# [6, [[[], []], [[], []]], [3, 3], [[], []]]",
|
|
1332
|
+
"; [(2 * [[], [], []]).##, ([[], []] * 3).##, (0 * [[]]).##]",
|
|
1333
|
+
"# [6, 6, 0]",
|
|
1334
|
+
"; [[], [[], []]] * [[]]",
|
|
1335
|
+
"# [[[]], [[[]], [[]]]]",
|
|
1336
|
+
"; [.tag 1;] * [[]]",
|
|
1337
|
+
"# $!.star-metadata *",
|
|
1330
1338
|
"```",
|
|
1331
1339
|
"Importing skips the examples and ends on a native true value.",
|
|
1332
1340
|
"```",
|
|
@@ -1491,6 +1499,60 @@ export const HC_SOURCES = new Map([
|
|
|
1491
1499
|
"",
|
|
1492
1500
|
].join("\n"),
|
|
1493
1501
|
],
|
|
1502
|
+
[
|
|
1503
|
+
"hc/membership.hc",
|
|
1504
|
+
[
|
|
1505
|
+
"#!/usr/bin/env hc",
|
|
1506
|
+
"```",
|
|
1507
|
+
"On ordinary element hosts, immediate membership follows the equality ladder: ~ uses =, ~~ uses ==,",
|
|
1508
|
+
"and ~~~ uses ===. The host is on the right. No descendant search or metadata.",
|
|
1509
|
+
"On schema/runtime matcher hosts, ~ retains rich matcher acceptance.",
|
|
1510
|
+
"```",
|
|
1511
|
+
"; [] ~ [[]]",
|
|
1512
|
+
"# <>",
|
|
1513
|
+
"; [] ~~ [[]]",
|
|
1514
|
+
"# <>",
|
|
1515
|
+
"; [] ~~~ [[]]",
|
|
1516
|
+
"# ()",
|
|
1517
|
+
"; 2 ~ [5 - 3]",
|
|
1518
|
+
"# <>",
|
|
1519
|
+
"; 2 ~~ [5 - 3]",
|
|
1520
|
+
"# ()",
|
|
1521
|
+
"; [] ~ [[[]]]",
|
|
1522
|
+
"# ()",
|
|
1523
|
+
"; 1 ~ [.property 1;]",
|
|
1524
|
+
"# ()",
|
|
1525
|
+
"```",
|
|
1526
|
+
"Fano incidence uses shared point objects. Equal form alone is not incidence.",
|
|
1527
|
+
"```",
|
|
1528
|
+
".point [];",
|
|
1529
|
+
".other [];",
|
|
1530
|
+
".line [point];",
|
|
1531
|
+
"; [other ~ line, other ~~ line, other ~~~ line, point ~~~ line]",
|
|
1532
|
+
"# [<>, <>, (), <>]",
|
|
1533
|
+
"; point ~~~ line",
|
|
1534
|
+
"# <>",
|
|
1535
|
+
"; other ~~~ line",
|
|
1536
|
+
"# ()",
|
|
1537
|
+
"```",
|
|
1538
|
+
"Runtime types use .<>; declared binding schemas use .<^>.",
|
|
1539
|
+
"Schema matching with ~ retains its nested contract.",
|
|
1540
|
+
"```",
|
|
1541
|
+
"; “Q” ~ “”.<>",
|
|
1542
|
+
"# <>",
|
|
1543
|
+
"; “Q” ~ 1.<>",
|
|
1544
|
+
"# ()",
|
|
1545
|
+
"; “”.<> “Q”",
|
|
1546
|
+
"# “Q”",
|
|
1547
|
+
"; {.f {missing}; “x” ~ f.<>} ()",
|
|
1548
|
+
"# ()",
|
|
1549
|
+
"; {.x <1, 2> 1; x.<^>} ()",
|
|
1550
|
+
"# <1, 2>",
|
|
1551
|
+
"; 0b101 ~ <3@Bit>",
|
|
1552
|
+
"# <>",
|
|
1553
|
+
"",
|
|
1554
|
+
].join("\n"),
|
|
1555
|
+
],
|
|
1494
1556
|
[
|
|
1495
1557
|
"hc/numerics.hc",
|
|
1496
1558
|
[
|
|
@@ -1602,7 +1664,7 @@ export const HC_SOURCES = new Map([
|
|
|
1602
1664
|
"; [3 xs, xs]",
|
|
1603
1665
|
"# [[1, 2, 1, 2, 1, 2], [1, 2]]",
|
|
1604
1666
|
"; [(1 xs) = xs, (1 xs) === xs, ((3 [xs]) .2) === xs, (2 [[1, 2]]).##]",
|
|
1605
|
-
"# [<>, (), <>,
|
|
1667
|
+
"# [<>, (), <>, 6]",
|
|
1606
1668
|
"```",
|
|
1607
1669
|
"Cross-rung promotion and integer-only modulo",
|
|
1608
1670
|
"```",
|
|
@@ -1701,7 +1763,7 @@ export const HC_SOURCES = new Map([
|
|
|
1701
1763
|
"# -2",
|
|
1702
1764
|
"```",
|
|
1703
1765
|
"Comparison and `=` compare values across rungs, so a count and a FrameInt of the",
|
|
1704
|
-
"same value are `=`. `==`, `===` and
|
|
1766
|
+
"same value are `=`. `==`, `===` and runtime types from `.<>` compare exact types, so the two are",
|
|
1705
1767
|
"not `==`, just as `2` and `2.0` are not",
|
|
1706
1768
|
"```",
|
|
1707
1769
|
"; 2 = (5 - 3)",
|
|
@@ -1716,10 +1778,10 @@ export const HC_SOURCES = new Map([
|
|
|
1716
1778
|
"# ()",
|
|
1717
1779
|
"; 2 == 2.0",
|
|
1718
1780
|
"# ()",
|
|
1719
|
-
";
|
|
1720
|
-
"# $!.type-error
|
|
1721
|
-
";
|
|
1722
|
-
"# $!.type-error
|
|
1781
|
+
"; (2).<> (5 - 3)",
|
|
1782
|
+
"# $!.type-error (2).<> 2",
|
|
1783
|
+
"; (5 - 3).<> 2",
|
|
1784
|
+
"# $!.type-error (2).<> 2",
|
|
1723
1785
|
"; (0 - 1).< 0",
|
|
1724
1786
|
"# <>",
|
|
1725
1787
|
"; 2.<= (5 - 3)",
|
|
@@ -1727,15 +1789,15 @@ export const HC_SOURCES = new Map([
|
|
|
1727
1789
|
"; 2.< 2.5",
|
|
1728
1790
|
"# <>",
|
|
1729
1791
|
"```",
|
|
1730
|
-
"Within one rung, `==` and
|
|
1792
|
+
"Within one rung, `==` and type application hold as they always have",
|
|
1731
1793
|
"```",
|
|
1732
1794
|
"; 2 == (1 + 1)",
|
|
1733
1795
|
"# <>",
|
|
1734
1796
|
"; (5 - 3) == (4 - 2)",
|
|
1735
1797
|
"# <>",
|
|
1736
|
-
";
|
|
1798
|
+
"; (2).<> 3",
|
|
1737
1799
|
"# 3",
|
|
1738
|
-
";
|
|
1800
|
+
"; (0 - 1).<> (0 - 5)",
|
|
1739
1801
|
"# -5",
|
|
1740
1802
|
"",
|
|
1741
1803
|
].join("\n"),
|
|
@@ -2004,9 +2066,9 @@ export const HC_SOURCES = new Map([
|
|
|
2004
2066
|
"# <>",
|
|
2005
2067
|
"; 2 ~ ()",
|
|
2006
2068
|
"# ()",
|
|
2007
|
-
"; “Q” ~
|
|
2069
|
+
"; “Q” ~ (“”).<>",
|
|
2008
2070
|
"# <>",
|
|
2009
|
-
"; “Q” ~
|
|
2071
|
+
"; “Q” ~ (1).<>",
|
|
2010
2072
|
"# ()",
|
|
2011
2073
|
"## Closure signatures apply defaults, require bare fields, and allow extras",
|
|
2012
2074
|
"; .join-name (.first “Jane”, .last) ^ {last “, ” first};",
|
|
@@ -3136,12 +3198,12 @@ export const HC_SOURCES = new Map([
|
|
|
3136
3198
|
"",
|
|
3137
3199
|
"#### Type Values",
|
|
3138
3200
|
"",
|
|
3139
|
-
"The simplest way to construct a type is to use the
|
|
3201
|
+
"The simplest way to construct a type is to use the `.<>` accessor to extract the runtime type",
|
|
3140
3202
|
"of a known object:",
|
|
3141
3203
|
"```",
|
|
3142
|
-
"; “Q” ~
|
|
3204
|
+
"; “Q” ~ (“”).<>",
|
|
3143
3205
|
"# <>",
|
|
3144
|
-
"; “Q” ~
|
|
3206
|
+
"; “Q” ~ (1).<>",
|
|
3145
3207
|
"# ()",
|
|
3146
3208
|
"```",
|
|
3147
3209
|
"### 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
|
}
|
|
@@ -120,7 +120,7 @@ export class FrameExpr extends FrameList {
|
|
|
120
120
|
}
|
|
121
121
|
schemaRetrieval(scope) {
|
|
122
122
|
if (this.data.length !== 2 || !(this.data[0] instanceof FrameSymbol) ||
|
|
123
|
-
!(this.data[1] instanceof FrameName) || this.data[1].source !== "
|
|
123
|
+
!(this.data[1] instanceof FrameName) || this.data[1].source !== "<^>")
|
|
124
124
|
return undefined;
|
|
125
125
|
return this.data[0].bindingSchema(resumedScope(this.data[0], scope));
|
|
126
126
|
}
|
|
@@ -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";
|
|
@@ -124,6 +125,9 @@ export class FrameLazy extends FrameExpr {
|
|
|
124
125
|
}
|
|
125
126
|
/** Evaluates this closure with optional bound receiver capability. */
|
|
126
127
|
call(argument, parameter = Frame.nil, receiverState) {
|
|
128
|
+
if (argument instanceof FrameSymbol && argument.is.address === true &&
|
|
129
|
+
argument.spelling() === "<>")
|
|
130
|
+
return FrameType.of(this);
|
|
127
131
|
const size = this.sizeOperator(argument);
|
|
128
132
|
if (size)
|
|
129
133
|
return size;
|
|
@@ -156,9 +156,9 @@ export class FrameList extends Frame {
|
|
|
156
156
|
/**
|
|
157
157
|
* The terminals of this aggregate's structure, the nodes with no elements
|
|
158
158
|
* below them. An aggregate with no elements is itself one terminal, at the
|
|
159
|
-
* root or nested, so `[]` counts 1
|
|
160
|
-
*
|
|
161
|
-
*
|
|
159
|
+
* root or nested, so `[]` counts 1. A nonempty aggregate counts its elements' terminals: each
|
|
160
|
+
* count element contributes its count (including zero); another atom is one
|
|
161
|
+
* terminal, and each aggregate
|
|
162
162
|
* element counts its own, at any depth. Properties are not elements, so an
|
|
163
163
|
* aggregate holding only properties is one terminal too.
|
|
164
164
|
*
|
|
@@ -180,7 +180,11 @@ export class FrameList extends Frame {
|
|
|
180
180
|
let terminals = 0n;
|
|
181
181
|
for (const element of elements) {
|
|
182
182
|
const value = element.referent();
|
|
183
|
-
const below = value instanceof FrameList
|
|
183
|
+
const below = value instanceof FrameList
|
|
184
|
+
? value.terminalCount(path)
|
|
185
|
+
: value instanceof FrameCount
|
|
186
|
+
? value.data
|
|
187
|
+
: 1n;
|
|
184
188
|
if (below === undefined)
|
|
185
189
|
return undefined;
|
|
186
190
|
terminals += below;
|
|
@@ -20,7 +20,10 @@ const recognizeName = (symbol, source = "") => {
|
|
|
20
20
|
if (source.startsWith(".")) {
|
|
21
21
|
return { disposition: ScanDisposition.CompleteRedispatch };
|
|
22
22
|
}
|
|
23
|
-
|
|
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, `.#`, `.##`
|
|
@@ -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
|
|
@@ -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
|
|
37
|
+
return `(${this.representative.toString()}).<>`;
|
|
37
38
|
}
|
|
38
39
|
dataString() {
|
|
39
40
|
return this.toString();
|
package/esm/lib/frames/reread.js
CHANGED
|
@@ -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
|
|
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;
|
package/esm/lib/ops/math.js
CHANGED
|
@@ -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
|
-
|
|
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 {
|
|
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
|
-
"~":
|
|
31
|
+
"~": Member,
|
|
32
|
+
"~~": TypedMember,
|
|
33
|
+
"~~~": IdenticalMember,
|
|
31
34
|
"^": BindType,
|
|
32
35
|
});
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.36.1";
|