hclang 0.36.1 → 0.37.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 +88 -65
- package/esm/lib/frames/frame-array.js +3 -3
- package/esm/lib/frames/frame-blob.js +3 -0
- package/esm/lib/frames/frame-bytes.js +3 -0
- package/esm/lib/frames/frame-count.js +2 -0
- package/esm/lib/frames/frame-expr.js +64 -3
- package/esm/lib/frames/frame-group.js +3 -0
- package/esm/lib/frames/frame-handle.js +8 -2
- package/esm/lib/frames/frame-lazy.js +5 -6
- package/esm/lib/frames/frame-list.js +35 -96
- package/esm/lib/frames/frame-numeric.js +15 -0
- package/esm/lib/frames/frame-schema.js +8 -0
- package/esm/lib/frames/frame-text.js +9 -0
- package/esm/lib/frames/frame.js +38 -6
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -1164,71 +1164,57 @@ export const HC_SOURCES = new Map([
|
|
|
1164
1164
|
[
|
|
1165
1165
|
"#!/usr/bin/env hc",
|
|
1166
1166
|
"```",
|
|
1167
|
-
"Figures
|
|
1168
|
-
"",
|
|
1169
|
-
"A
|
|
1170
|
-
"
|
|
1171
|
-
"
|
|
1172
|
-
"
|
|
1173
|
-
"
|
|
1167
|
+
"Figures as projections of native HC frames (#454; occurrence/figure 010.09)",
|
|
1168
|
+
"",
|
|
1169
|
+
"A figure is a projection of HC frames through which we observe invariants that",
|
|
1170
|
+
"embody mathematical relations. This is a working definition: each investigation",
|
|
1171
|
+
"specifies its projection, transformations and invariants.",
|
|
1172
|
+
"",
|
|
1173
|
+
"Finite nested arrays built from `[]` are the simplest construction family used",
|
|
1174
|
+
"below. They do not define the full domain of native observations. Size, residual",
|
|
1175
|
+
"and immediate identity membership exclude properties and declared parents;",
|
|
1176
|
+
"Star keeps nonterminal metadata when rebuilding frames. Construction is brackets,",
|
|
1177
|
+
"form is the value itself, immediate arity is `.#`, Size is `.##`, form equality",
|
|
1178
|
+
"is `=`, and identity is `===`. The empty frame is one terminal: `[].#` is 0 and",
|
|
1179
|
+
"`[].##` is 1. The signed residual `.###` is",
|
|
1174
1180
|
"`x₁.## − x₂.## + x₃.## − …` over the immediate elements, a FrameInt that is 0",
|
|
1175
1181
|
"for `[]` (issue occurrence/figure 010.04).",
|
|
1176
1182
|
"",
|
|
1177
1183
|
"There are no Figure constructors, marks, tally observers, count aliases or",
|
|
1178
|
-
"comparison wrappers. Use native operations directly. Star `x * y` places y at
|
|
1184
|
+
"comparison wrappers. Use native operations directly. Star `x * y` places y at",
|
|
1185
|
+
"each terminal of x, preserving nesting.",
|
|
1179
1186
|
"Flat repetition is `x.## [y]`. A tally, when wanted, is an explicit",
|
|
1180
1187
|
"construction, such as `x & {[[]]}` for one fresh mark per immediate element.",
|
|
1181
|
-
"Native `.##`
|
|
1182
|
-
"
|
|
1183
|
-
"
|
|
1184
|
-
"",
|
|
1185
|
-
"Only
|
|
1186
|
-
"
|
|
1187
|
-
"
|
|
1188
|
-
"
|
|
1189
|
-
"
|
|
1190
|
-
"
|
|
1191
|
-
"
|
|
1192
|
-
"
|
|
1193
|
-
"
|
|
1194
|
-
"
|
|
1195
|
-
"```",
|
|
1196
|
-
"
|
|
1197
|
-
"```",
|
|
1198
|
-
".need {.x _; (pure x) ? {x} : {unsupported-figure}};",
|
|
1199
|
-
"```",
|
|
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
|
-
"",
|
|
1206
|
-
"`withness x [f, …]` asks whether every requested frame is an immediate element",
|
|
1207
|
-
"of x by native identity. It returns a native boolean. No requested frames is true.",
|
|
1208
|
-
"```",
|
|
1209
|
-
".withness {.x _; .host x;",
|
|
1210
|
-
" {.fs _;",
|
|
1211
|
-
" .absent (fs &| {.f _; (f ~~~ host) ? {[]} : {[f]}});",
|
|
1212
|
-
" absent = []}};",
|
|
1213
|
-
"```",
|
|
1214
|
-
"`gap x` is the absolute value of native `x.###`, the alternating sum of its",
|
|
1215
|
-
"immediate elements' `.##` counts, always a nonnegative FrameInt (Owner decision",
|
|
1216
|
-
"for #455). The empty frame has Gap 0 as a FrameInt too.",
|
|
1217
|
-
"```",
|
|
1218
|
-
".gap {.x _; (pure x) ? {",
|
|
1188
|
+
"Native `.##` uses each child's native Size, including numeric magnitude and",
|
|
1189
|
+
"text length. Native `.###` also accepts mixed arrays and evaluated groups.",
|
|
1190
|
+
"Star keeps its narrower array/Count composition domain.",
|
|
1191
|
+
"",
|
|
1192
|
+
"Only two derived mathematical abbreviations remain: Gap = |signed residual|",
|
|
1193
|
+
"and Spin = signed residual / positive Count. They define no Figure domain.",
|
|
1194
|
+
"Incidence is native `point ~~~ line`; collective incidence uses ordinary",
|
|
1195
|
+
"iteration. Observer eligibility is `x.###` itself: a FrameInt, including zero,",
|
|
1196
|
+
"is true; an unsupported host answers nil. No `pure`, `need` or `withness`",
|
|
1197
|
+
"helper is exported (issue occurrence/figure 010.09).",
|
|
1198
|
+
"",
|
|
1199
|
+
"Gap keeps a FrameInt result. Using `(x.###).##` instead would change the type",
|
|
1200
|
+
"to Count and would even give Size 1 for an unsupported host's nil. Test residual",
|
|
1201
|
+
"availability directly, then bind its value and choose its sign with native HC.",
|
|
1202
|
+
"```",
|
|
1203
|
+
".gap {.x _; (x.###) ? {",
|
|
1219
1204
|
" .signed (x.###);",
|
|
1220
|
-
" (signed .< 0) ? {0 - signed} : {signed}} : {
|
|
1205
|
+
" (signed .< 0) ? {0 - signed} : {signed}} : {unsupported-figure}};",
|
|
1221
1206
|
"```",
|
|
1222
|
-
"
|
|
1223
|
-
"
|
|
1224
|
-
"before
|
|
1207
|
+
"Spin retains a typed positive Count divisor. Bare `x.### / N` would accept",
|
|
1208
|
+
"negative or fractional divisors and silently answer nil for an unsupported",
|
|
1209
|
+
"host. This abbreviation keeps host refusal before divisor validation, Count",
|
|
1210
|
+
"type errors, and division-by-zero even for a zero residual. These two short",
|
|
1211
|
+
"definitions are mathematical conveniences, not constructors or type guards.",
|
|
1225
1212
|
"```",
|
|
1226
1213
|
".spin {.x _; .host x;",
|
|
1227
|
-
" (
|
|
1228
|
-
" {.n <(1).<>> _;",
|
|
1229
|
-
" .signed (host.###);",
|
|
1214
|
+
" (host.###) ? {",
|
|
1215
|
+
" {.n <(1).<>> _; .signed (host.###);",
|
|
1230
1216
|
" (n .< 1) ? {signed / 0} : {signed / n}}} : {",
|
|
1231
|
-
" {.n _;
|
|
1217
|
+
" {.n _; unsupported-figure}}};",
|
|
1232
1218
|
"```",
|
|
1233
1219
|
"Native construction, counting and comparisons need no module helpers.",
|
|
1234
1220
|
"```",
|
|
@@ -1240,18 +1226,18 @@ export const HC_SOURCES = new Map([
|
|
|
1240
1226
|
"; [e.## = [[], []].##, [].## = [[]].##]",
|
|
1241
1227
|
"# [<>, <>]",
|
|
1242
1228
|
"```",
|
|
1243
|
-
"Native
|
|
1229
|
+
"Native observations need no domain wrapper, enumeration or tally construction.",
|
|
1244
1230
|
"```",
|
|
1245
|
-
"; [(
|
|
1246
|
-
"# [<>, <>,
|
|
1247
|
-
"; [(
|
|
1231
|
+
"; [([].### ? {<>} : {()}), ([[], [[]]].### ? {<>} : {()}), ([[], 5].### ? {<>} : {()}), ([.k 1; []].### ? {<>} : {()})]",
|
|
1232
|
+
"# [<>, <>, <>, <>]",
|
|
1233
|
+
"; [(e.### ? {e} : {unsupported-figure}) = e, (e.### ? {e} : {unsupported-figure}) === e]",
|
|
1248
1234
|
"# [<>, <>]",
|
|
1249
1235
|
"; [[], “a”] * [[]]",
|
|
1250
1236
|
"# $!.star-domain *",
|
|
1251
1237
|
"; (0 - 5) * [[]]",
|
|
1252
1238
|
"# $!.star-domain *",
|
|
1253
1239
|
"; gap ([], [[], []])",
|
|
1254
|
-
"#
|
|
1240
|
+
"# 1",
|
|
1255
1241
|
"```",
|
|
1256
1242
|
"Properties and declared parents never decide the observer domain or an observation.",
|
|
1257
1243
|
"Star preserves metadata on rebuilt nonterminal ancestors and leaves its host",
|
|
@@ -1282,17 +1268,28 @@ export const HC_SOURCES = new Map([
|
|
|
1282
1268
|
"; [([[[], []]].## [[[]]]) = [[[]], [[]]], ([[[], []]] * [[]]) = [[[[]], [[]]]]]",
|
|
1283
1269
|
"# [<>, <>]",
|
|
1284
1270
|
"```",
|
|
1285
|
-
"
|
|
1271
|
+
"Incidence uses immediate identity. These shared frame objects illustrate Fano",
|
|
1272
|
+
"incidence (see `hc/membership.hc`; occurrence/figure 010.06), without claiming",
|
|
1273
|
+
"that the complete Fano geometry has been derived. Equal form is not incidence.",
|
|
1274
|
+
"Collective incidence keeps the absent requested points and asks if none remain;",
|
|
1275
|
+
"empty requests are true, repeats need one match, and nested-only points fail.",
|
|
1286
1276
|
"```",
|
|
1287
1277
|
"; .shared [[]]; .p1 [shared, []]; .p2 [[], shared];",
|
|
1288
|
-
"; [
|
|
1278
|
+
"; [shared ~~~ p1, shared ~~~ p2, [[]] ~~~ p1]",
|
|
1289
1279
|
"# [<>, <>, ()]",
|
|
1290
|
-
"; [
|
|
1280
|
+
"; [[[]] ~~~ [], ([] &| {.f _; (f ~~~ p1) ? {[]} : {[f]}}) = []]",
|
|
1291
1281
|
"# [(), <>]",
|
|
1282
|
+
"; ([shared, shared] &| {.f _; (f ~~~ p1) ? {[]} : {[f]}}) = []",
|
|
1283
|
+
"# <>",
|
|
1284
|
+
"; ([shared, [[]]] &| {.f _; (f ~~~ p1) ? {[]} : {[f]}}) = []",
|
|
1285
|
+
"# ()",
|
|
1286
|
+
"; .nested [p1];",
|
|
1287
|
+
"; ([shared] &| {.f _; (f ~~~ nested) ? {[]} : {[f]}}) = []",
|
|
1288
|
+
"# ()",
|
|
1292
1289
|
"```",
|
|
1293
|
-
"Native `.###` folds the immediate elements'
|
|
1290
|
+
"Native `.###` folds the immediate elements' Sizes with alternating",
|
|
1294
1291
|
"signs, one sign per element, and answers a FrameInt even when it is 0 or",
|
|
1295
|
-
"positive.
|
|
1292
|
+
"positive. Mixed arrays and evaluated groups use the same rule.",
|
|
1296
1293
|
"```",
|
|
1297
1294
|
"; [[].###, [[]].###, [[], []].###, [[], [[], []]].###, [[[], []], []].###]",
|
|
1298
1295
|
"# [0, 1, 0, -1, 1]",
|
|
@@ -1303,8 +1300,28 @@ export const HC_SOURCES = new Map([
|
|
|
1303
1300
|
"; [[[], [[]]], [[[], []], []], [[[[], [], []]]]].###",
|
|
1304
1301
|
"# 2",
|
|
1305
1302
|
"; [[1, []].###, [[], “ab”].###, [[], ([], [])].###, 5.###]",
|
|
1306
|
-
"# [
|
|
1303
|
+
"# [0, -1, -1, ()]",
|
|
1304
|
+
"```",
|
|
1305
|
+
"Native Size also measures mixed values, independently of structural Star.",
|
|
1306
|
+
"Numeric magnitude truncates exactly; text length uses native Unicode code-point iteration,",
|
|
1307
|
+
"blob width uses bits, and schemas count declared alternatives.",
|
|
1308
|
+
"```",
|
|
1309
|
+
"; [(7.9).##, (-7.9).##, (-3).##, (0.9).##, 0.##, (-7 / 2).##]",
|
|
1310
|
+
"# [7, 7, 3, 0, 0, 3]",
|
|
1311
|
+
"; [“”.##, “hello”.##, “é😀”.##, 0x00ff.##]",
|
|
1312
|
+
"# [0, 5, 2, 16]",
|
|
1313
|
+
"; [(1).<>.##, <2, 3, 5>.##, <2, 2, [3, 5]>.##, <.a, .b>.##, <>.##]",
|
|
1314
|
+
"# [1, 3, 3, 1, 1]",
|
|
1315
|
+
"; [[5, “hello”].##, [5, “hello”].###, (5, 3).###, [5, 3, 2, 7].###]",
|
|
1316
|
+
"# [10, 0, 2, -3]",
|
|
1317
|
+
"; [([5, “hello”].### ? {<>} : {()}), (5.### ? {<>} : {()})]",
|
|
1318
|
+
"# [<>, ()]",
|
|
1319
|
+
"; { .x <[].<>> _; x.### } [[], [“nested atom”]]",
|
|
1320
|
+
"# -10",
|
|
1307
1321
|
"```",
|
|
1322
|
+
"Outer array binding accepts nested atoms, and rejects groups despite their valid",
|
|
1323
|
+
"residual. It is neither a recursive array-only constraint nor the residual domain.",
|
|
1324
|
+
"",
|
|
1308
1325
|
"Gap is `|x.###|` and Spin is `x.### / N`, including shared branches at every",
|
|
1309
1326
|
"occurrence. Reversing two unequal branches reverses Spin's sign.",
|
|
1310
1327
|
"```",
|
|
@@ -1323,6 +1340,12 @@ export const HC_SOURCES = new Map([
|
|
|
1323
1340
|
"# $!.type-error .n <(1).<>> 2.5",
|
|
1324
1341
|
"; spin [[[], []]] 0",
|
|
1325
1342
|
"# $!.division-by-zero /",
|
|
1343
|
+
"; [gap [5, “hello”], spin [5, “hello”] 4]",
|
|
1344
|
+
"# [0, 0]",
|
|
1345
|
+
"; spin [] (0 - 2)",
|
|
1346
|
+
"# $!.type-error .n <(1).<>> -2",
|
|
1347
|
+
"; spin [] 0",
|
|
1348
|
+
"# $!.division-by-zero /",
|
|
1326
1349
|
"",
|
|
1327
1350
|
"```",
|
|
1328
1351
|
"Star uses native `*` dispatch; numeric pairs keep arithmetic.",
|
|
@@ -138,10 +138,10 @@ export class FrameArray extends FrameList {
|
|
|
138
138
|
return true;
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
141
|
+
* An evaluated array exposes ordered data for residual; properties and
|
|
142
|
+
* declared parents are excluded.
|
|
143
143
|
*/
|
|
144
|
-
|
|
144
|
+
supportsResidual() {
|
|
145
145
|
return true;
|
|
146
146
|
}
|
|
147
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);
|
|
@@ -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
|
}
|
|
@@ -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
|
|
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.
|
|
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
|
|
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);
|
|
@@ -93,12 +93,11 @@ export class FrameLazy extends FrameExpr {
|
|
|
93
93
|
: undefined;
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* (010.
|
|
100
|
-
* reaches a closure as its argument
|
|
101
|
-
* 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.
|
|
102
101
|
*/
|
|
103
102
|
sizeOperator(argument) {
|
|
104
103
|
if (argument instanceof FrameSymbol && argument.is.address === true &&
|
|
@@ -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,124 +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
|
-
|
|
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
|
-
|
|
158
|
-
* below them. An aggregate with no elements is itself one terminal, at the
|
|
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
|
-
* 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
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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);
|
|
191
174
|
}
|
|
192
|
-
path.delete(this);
|
|
193
|
-
return terminals;
|
|
194
175
|
}
|
|
195
|
-
/**
|
|
196
|
-
|
|
197
|
-
* (010.04). Only an array can, so groups, schemas and closures answer false
|
|
198
|
-
* here. Properties are not elements, so they never decide it.
|
|
199
|
-
*/
|
|
200
|
-
isFigureNode() {
|
|
176
|
+
/** Only concrete ordered data hosts opt in, never executable/matcher syntax. */
|
|
177
|
+
supportsResidual() {
|
|
201
178
|
return false;
|
|
202
179
|
}
|
|
203
|
-
/**
|
|
204
|
-
* `.###`, the signed alternating sum of the terminal counts of a Figure's
|
|
205
|
-
* immediate elements, `T(x₁) − T(x₂) + T(x₃) − …`, always a FrameInt and 0
|
|
206
|
-
* for `[]` (issue occurrence/figure 010.04). A terminal is an empty frame,
|
|
207
|
-
* so on a Figure `T` is `.##`. Each element is folded with one sign; the
|
|
208
|
-
* signs do not alternate over the terminals below it.
|
|
209
|
-
*
|
|
210
|
-
* A Figure is read through its elements only, so properties and a declared
|
|
211
|
-
* parent are ignored at every level, as `.#` and `.##` ignore them. Anything
|
|
212
|
-
* else is not a Figure and answers nil, as `.#` does for a non-aggregate:
|
|
213
|
-
* an atom, a string, a group, a schema or a closure anywhere in the
|
|
214
|
-
* structure, or an aggregate that contains itself.
|
|
215
|
-
*/
|
|
180
|
+
/** Alternate over immediate positions, using each child's complete Size. */
|
|
216
181
|
residual() {
|
|
217
|
-
if (!this.
|
|
182
|
+
if (!this.supportsResidual() || this.is.source === true)
|
|
218
183
|
return Frame.nil;
|
|
219
184
|
const path = new Set([this]);
|
|
220
185
|
let signed = 0n;
|
|
221
186
|
let positive = true;
|
|
222
187
|
for (const element of this.countedElements()) {
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
188
|
+
const size = element.referent().nativeSize(path);
|
|
189
|
+
if (typeof size !== "bigint")
|
|
225
190
|
return Frame.nil;
|
|
226
|
-
signed += positive ?
|
|
191
|
+
signed += positive ? size : -size;
|
|
227
192
|
positive = !positive;
|
|
228
193
|
}
|
|
229
194
|
return new FrameInt(signed);
|
|
230
195
|
}
|
|
231
|
-
/**
|
|
232
|
-
* The terminal count of `value` as a Figure: 1 for an empty frame, else the
|
|
233
|
-
* sum over its elements. Answers undefined when any node is not a Figure
|
|
234
|
-
* node or contains itself. `path` holds the nodes from the root down, as
|
|
235
|
-
* for `terminalCount`, so a shared branch counts at every occurrence.
|
|
236
|
-
*/
|
|
237
|
-
static figureTerminals(value, path) {
|
|
238
|
-
if (!(value instanceof FrameList) || !value.isFigureNode()) {
|
|
239
|
-
return undefined;
|
|
240
|
-
}
|
|
241
|
-
if (path.has(value))
|
|
242
|
-
return undefined;
|
|
243
|
-
const elements = value.countedElements();
|
|
244
|
-
if (elements.length === 0)
|
|
245
|
-
return 1n;
|
|
246
|
-
path.add(value);
|
|
247
|
-
let terminals = 0n;
|
|
248
|
-
for (const element of elements) {
|
|
249
|
-
const below = FrameList.figureTerminals(element.referent(), path);
|
|
250
|
-
if (below === undefined)
|
|
251
|
-
return undefined;
|
|
252
|
-
terminals += below;
|
|
253
|
-
}
|
|
254
|
-
path.delete(value);
|
|
255
|
-
return terminals;
|
|
256
|
-
}
|
|
257
196
|
/**
|
|
258
197
|
* `n x` for an aggregate concatenates (v0.22.0). The answer is a fresh
|
|
259
198
|
* aggregate of x's kind holding the terms x keeps once, its properties and
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
package/esm/lib/frames/frame.js
CHANGED
|
@@ -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).
|
|
249
|
-
*
|
|
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(
|
|
253
|
-
|
|
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
|
})()
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.37.1";
|