hclang 0.23.0 → 0.23.2
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 +50 -12
- package/esm/lib/frames/evaluation-scope.js +10 -0
- package/esm/lib/frames/frame-arg.js +1 -1
- package/esm/lib/frames/frame-array.js +8 -0
- package/esm/lib/frames/frame-handle.js +4 -0
- package/esm/lib/frames/frame-int.js +6 -1
- package/esm/lib/frames/frame.js +8 -0
- package/esm/lib/ops/iterators.js +13 -4
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -449,6 +449,25 @@ export const HC_SOURCES = new Map([
|
|
|
449
449
|
"; [1, 2, 4] | 1",
|
|
450
450
|
"# 8",
|
|
451
451
|
"```",
|
|
452
|
+
"## A map keeps its answers apart, from a literal too",
|
|
453
|
+
"",
|
|
454
|
+
"**Decision.** A map never accumulates into its receiver (#417). Each element is",
|
|
455
|
+
"applied to the receiver's collecting copy, a fresh aggregate holding the same",
|
|
456
|
+
"members, as applying through an immutable name already does. A reduce may",
|
|
457
|
+
"write its fresh accumulator in place, since only the final answer escapes, but",
|
|
458
|
+
"a map answers once per element. Before v0.23.1 an aggregate that no name held",
|
|
459
|
+
"collected every element and was answered each time, so `[1, 2] & [0]` was one",
|
|
460
|
+
"array `[0, 1, 2]`, twice",
|
|
461
|
+
"```",
|
|
462
|
+
"; [1, 2, 3] & []",
|
|
463
|
+
"# [[1], [2], [3]]",
|
|
464
|
+
"; .m ([1, 2] & [0]);",
|
|
465
|
+
"; [m, (m .0) === (m .1)]",
|
|
466
|
+
"# [[[0, 1], [0, 2]], ()]",
|
|
467
|
+
"; .r [0];",
|
|
468
|
+
"; [([1, 2] & r) = m, r]",
|
|
469
|
+
"# [<>, [0]]",
|
|
470
|
+
"```",
|
|
452
471
|
"## A name applies like the value it names",
|
|
453
472
|
"",
|
|
454
473
|
"**Decision.** Naming a receiver does not change what applying it answers, so a",
|
|
@@ -477,6 +496,20 @@ export const HC_SOURCES = new Map([
|
|
|
477
496
|
"; [((row xs) .2) === xs, (row xs) === row]",
|
|
478
497
|
"# [<>, ()]",
|
|
479
498
|
"```",
|
|
499
|
+
"An argument applies like a name, too (#419). A value an operation is handed,",
|
|
500
|
+
"an element a map gives its block or the operand of a repetition, is read-only:",
|
|
501
|
+
"applying it collects onto a copy, and its declared `apply_` answers a",
|
|
502
|
+
"functional update. Only what the operation created, a fresh literal or a",
|
|
503
|
+
"reduce's own accumulator, is written in place",
|
|
504
|
+
"```",
|
|
505
|
+
"; .nest [[1], [2]];",
|
|
506
|
+
"; [nest & {_ 9}, nest]",
|
|
507
|
+
"# [[[1, 9], [2, 9]], [[1], [2]]]",
|
|
508
|
+
"; .Acc {[.n _; .apply_ {@n (_^.n + 1);}]};",
|
|
509
|
+
"; .acc (Acc 0);",
|
|
510
|
+
"; [(3 acc).n, acc.n]",
|
|
511
|
+
"# [2, 0]",
|
|
512
|
+
"```",
|
|
480
513
|
"Concatenation therefore needs no operator of its own: reduce one aggregate into",
|
|
481
514
|
"another, named or computed",
|
|
482
515
|
"```",
|
|
@@ -803,12 +836,6 @@ export const HC_SOURCES = new Map([
|
|
|
803
836
|
"",
|
|
804
837
|
"## What this file does not decide",
|
|
805
838
|
"",
|
|
806
|
-
"- whether an aggregate in a map refuses. The notes refused it, on the ground",
|
|
807
|
-
" that one accumulator cannot serve one answer per input. But `[1, 2, 3] & []`",
|
|
808
|
-
" is ordinary application — each element collects into the array, which answers",
|
|
809
|
-
" itself, so the map answers three references to one array. That is useless",
|
|
810
|
-
" rather than incoherent, and refusing it is the same paternalism the closure",
|
|
811
|
-
' form was retired for. It needs an argument beyond "you probably meant `|`";',
|
|
812
839
|
"- whether a string should enumerate characters, closing a11's asymmetry;",
|
|
813
840
|
"- what a receiver answering nil mid-reduce does when it declares no",
|
|
814
841
|
" application. A declared application keeps its receiver on nil, but a closure",
|
|
@@ -1146,11 +1173,13 @@ export const HC_SOURCES = new Map([
|
|
|
1146
1173
|
"```;",
|
|
1147
1174
|
" .children (_ | []);",
|
|
1148
1175
|
"```",
|
|
1149
|
-
"**Application**, `x y` (#375):
|
|
1150
|
-
"
|
|
1151
|
-
"
|
|
1176
|
+
"**Application**, `x y` (#375): x's children followed by y. It is a mutating",
|
|
1177
|
+
"method, `apply_`, so through a name, `x y` is a functional update: it answers a",
|
|
1178
|
+
"new Figure and leaves x unchanged. A reduce writes only the Figure its own",
|
|
1179
|
+
"first step answered, so `ys | x` joins two Figures, copying x once, and",
|
|
1180
|
+
"`cs | (Figure [])` constructs one out of a stream. It forgets nothing",
|
|
1152
1181
|
"```;",
|
|
1153
|
-
" .
|
|
1182
|
+
" .apply_ {@children (_^.children _);};",
|
|
1154
1183
|
"```",
|
|
1155
1184
|
"**Manyness**, `x.many()`: a tally with one mark `B` per immediate child. It",
|
|
1156
1185
|
"keeps how many children there are and forgets what they are, everything below",
|
|
@@ -1272,9 +1301,18 @@ export const HC_SOURCES = new Map([
|
|
|
1272
1301
|
"```",
|
|
1273
1302
|
"Repetition applies a Figure rather than concatenating, because a Figure",
|
|
1274
1303
|
"declares its application: `3 U` is `(U U) U`, and each child it appends is `U`",
|
|
1275
|
-
"itself",
|
|
1304
|
+
"itself. U is the operand, never the receiver written",
|
|
1305
|
+
"```",
|
|
1306
|
+
"; [(3 U) = ((U U) U), ((3 U).children .0) === Z, ((3 U).children .2) === U, U = (Figure [Z])]",
|
|
1307
|
+
"# [<>, <>, <>, <>]",
|
|
1308
|
+
"```",
|
|
1309
|
+
"A join copies its receiver once and appends in place after that, so it is",
|
|
1310
|
+
"quick, and the receiver and every child keep their identity",
|
|
1276
1311
|
"```",
|
|
1277
|
-
";
|
|
1312
|
+
"; .joined ((512 [U]) | Z);",
|
|
1313
|
+
"; [joined.children.#, Z = (Figure []), (joined.children .511) === U]",
|
|
1314
|
+
"# [512, <>, <>]",
|
|
1315
|
+
"; [(E.children & {_ A}) = [Figure [A], Figure [Z, A]], A = (Figure []), B = (Figure [A])]",
|
|
1278
1316
|
"# [<>, <>, <>]",
|
|
1279
1317
|
"```",
|
|
1280
1318
|
"## Manyness and Size",
|
|
@@ -365,6 +365,16 @@ export class EvaluationScope {
|
|
|
365
365
|
}
|
|
366
366
|
return scope?.argument;
|
|
367
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* The argument `_`, `__`, ... as source reads it: an aggregate the call was
|
|
370
|
+
* handed raw is read through an immutable handle, as a name would read it,
|
|
371
|
+
* so applying it collects onto a copy and its mutating methods answer
|
|
372
|
+
* functional updates. An argument is never the call's to write (#419). A
|
|
373
|
+
* handle the caller passed, mutable or not, is kept as it is.
|
|
374
|
+
*/
|
|
375
|
+
argumentRead(level) {
|
|
376
|
+
return this.argumentAt(level)?.readOnly();
|
|
377
|
+
}
|
|
368
378
|
/** Resolves `.`, `..`, ... through exact enclosing call parameters. */
|
|
369
379
|
parameterAt(level) {
|
|
370
380
|
if (level <= 1)
|
|
@@ -38,7 +38,7 @@ export class FrameArg extends FrameSymbol {
|
|
|
38
38
|
in(input = []) {
|
|
39
39
|
const scope = EvaluationScope.from(input);
|
|
40
40
|
const level = this.data.length;
|
|
41
|
-
const target = scope.
|
|
41
|
+
const target = scope.argumentRead(level);
|
|
42
42
|
if (target)
|
|
43
43
|
return target;
|
|
44
44
|
// Outside a closure, an unresolved level remains an argument expression at
|
|
@@ -5,6 +5,7 @@ import { Frame } from "./frame.js";
|
|
|
5
5
|
import { BoundMethod } from "./bound-method.js";
|
|
6
6
|
import { methodEffect } from "./effect-marker.js";
|
|
7
7
|
import { FrameExpr } from "./frame-expr.js";
|
|
8
|
+
import { FrameHandle } from "./frame-handle.js";
|
|
8
9
|
import { FrameList } from "./frame-list.js";
|
|
9
10
|
import { FrameNote } from "./frame-note.js";
|
|
10
11
|
import { NilContext } from "./context.js";
|
|
@@ -61,6 +62,13 @@ export class FrameArray extends FrameList {
|
|
|
61
62
|
ownsIdentity() {
|
|
62
63
|
return true;
|
|
63
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* An immutable handle on this aggregate, as a name reads it: applying it
|
|
67
|
+
* collects onto a copy and its mutating methods answer functional updates.
|
|
68
|
+
*/
|
|
69
|
+
readOnly() {
|
|
70
|
+
return new FrameHandle(this, false);
|
|
71
|
+
}
|
|
64
72
|
/**
|
|
65
73
|
* `=` compares the complete view, the same one `&&` iterates: visible
|
|
66
74
|
* properties in declaration order, then elements by index, each by `=`.
|
|
@@ -98,6 +98,10 @@ export class FrameHandle extends Frame {
|
|
|
98
98
|
this.target = copy;
|
|
99
99
|
return copy;
|
|
100
100
|
}
|
|
101
|
+
/** A handle already says whether its reader may write; keep it as it is. */
|
|
102
|
+
readOnly() {
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
101
105
|
/** A handle is transparent to equality: it compares as its target. */
|
|
102
106
|
referent() {
|
|
103
107
|
return this.target.referent();
|
|
@@ -192,9 +192,14 @@ export class FrameInt extends FrameNumeric {
|
|
|
192
192
|
REPETITION_TEXT_LIMIT) {
|
|
193
193
|
return Frame.error(`$!.repetition-size ${REPETITION_TEXT_LIMIT}`);
|
|
194
194
|
}
|
|
195
|
+
// The operand arrives unwrapped, and applying to nil answers it as it is.
|
|
196
|
+
// Read it as a name would, so a later step that writes, such as a declared
|
|
197
|
+
// `apply_`, updates a copy rather than the operand itself (#419).
|
|
198
|
+
const operand = argument.readOnly();
|
|
195
199
|
let result = Frame.nil;
|
|
196
200
|
for (let index = 0; index < count; index += 1) {
|
|
197
|
-
|
|
201
|
+
const next = result.apply(operand, parameter);
|
|
202
|
+
result = next === operand.referent() ? operand : next;
|
|
198
203
|
}
|
|
199
204
|
return result;
|
|
200
205
|
}
|
package/esm/lib/frames/frame.js
CHANGED
|
@@ -253,6 +253,14 @@ export class Frame extends MetaFrame {
|
|
|
253
253
|
ownsIdentity() {
|
|
254
254
|
return false;
|
|
255
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* This frame as a value its reader may not write (#419). Only an aggregate
|
|
258
|
+
* owns identity a write can land on, so every other frame is its own
|
|
259
|
+
* read-only view; `FrameArray` answers an immutable handle on itself.
|
|
260
|
+
*/
|
|
261
|
+
readOnly() {
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
256
264
|
/** Compare only this frame's data plane, excluding metadata. */
|
|
257
265
|
dataEquals(other) {
|
|
258
266
|
return this.dataString() === other.dataString() ? Frame.all : Frame.nil;
|
package/esm/lib/ops/iterators.js
CHANGED
|
@@ -29,11 +29,20 @@ const members = (source) => {
|
|
|
29
29
|
const elements = source.elements().map((value, index) => tuple(index.toString(), value));
|
|
30
30
|
return [...properties, ...elements];
|
|
31
31
|
};
|
|
32
|
-
/**
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* `&` applies each element on its own and keeps the answers apart.
|
|
34
|
+
*
|
|
35
|
+
* A map never accumulates into its receiver (#417): each element is applied
|
|
36
|
+
* to the receiver's collecting copy, a fresh aggregate sharing its members,
|
|
37
|
+
* as applying through an immutable name already does. A reduce may write its
|
|
38
|
+
* fresh intermediate in place because only the final answer escapes; a map
|
|
39
|
+
* answers once per element, so an aggregate that no name holds would
|
|
40
|
+
* otherwise collect every element and be answered each time.
|
|
41
|
+
*/
|
|
42
|
+
export const MapElements = (source, receiver, receiverState) => new FrameArray(source.elements().map((value) => receiver.collectingCopy().call(value, Frame.nil, receiverState)));
|
|
34
43
|
/** `|` threads each element through the receiver the last step answered. */
|
|
35
44
|
export const ReduceElements = (source, receiver, receiverState) => source.reduce(receiver, receiverState);
|
|
36
|
-
/** `&&` maps the same stream widened to `[key, value]` tuples. */
|
|
37
|
-
export const MapMembers = (source, receiver, receiverState) => new FrameArray(members(source).map((member) => receiver.call(member, Frame.nil, receiverState)));
|
|
45
|
+
/** `&&` maps the same stream widened to `[key, value]` tuples, as `&` does. */
|
|
46
|
+
export const MapMembers = (source, receiver, receiverState) => new FrameArray(members(source).map((member) => receiver.collectingCopy().call(member, Frame.nil, receiverState)));
|
|
38
47
|
/** `||` reduces that widened stream, threading exactly as `|` does. */
|
|
39
48
|
export const ReduceMembers = (source, receiver, receiverState) => Frame.reduceInto(members(source), receiver, receiverState);
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.23.
|
|
1
|
+
export const VERSION = "0.23.2";
|