hclang 0.22.0 → 0.23.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.
|
@@ -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",
|
|
@@ -803,12 +822,6 @@ export const HC_SOURCES = new Map([
|
|
|
803
822
|
"",
|
|
804
823
|
"## What this file does not decide",
|
|
805
824
|
"",
|
|
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
825
|
"- whether a string should enumerate characters, closing a11's asymmetry;",
|
|
813
826
|
"- what a receiver answering nil mid-reduce does when it declares no",
|
|
814
827
|
" application. A declared application keeps its receiver on nil, but a closure",
|
|
@@ -996,6 +1009,39 @@ export const HC_SOURCES = new Map([
|
|
|
996
1009
|
"; [(shelf.tick_ ()).count, shelf.count, (shelf.tick_ ()).item === shelf.item]",
|
|
997
1010
|
"# [1, 0, <>]",
|
|
998
1011
|
"",
|
|
1012
|
+
"`A method reaches its receiver one caret out, because the scope a method is",
|
|
1013
|
+
"written in is its aggregate, and a call binds it to the aggregate it was found",
|
|
1014
|
+
"on. An inherited method therefore reads the descendant, and bare names, which",
|
|
1015
|
+
"read the argument first, are not needed to reach it.`",
|
|
1016
|
+
"; .Base [.x “base”; .get {_^.x}];",
|
|
1017
|
+
"; .Kid [.^ Base; .x “kid”];",
|
|
1018
|
+
"; [Base.get(), Kid.get()]",
|
|
1019
|
+
"# [“base”, “kid”]",
|
|
1020
|
+
"; .Pt [.n 1; .peek {[n, _^.n]}];",
|
|
1021
|
+
"; Pt.peek [.n 7]",
|
|
1022
|
+
"# [7, 1]",
|
|
1023
|
+
"",
|
|
1024
|
+
"`A functional copy is its own receiver, so its methods read the fields the copy",
|
|
1025
|
+
"holds rather than those of the value it was copied from.`",
|
|
1026
|
+
"; .Tally [.n 1; .read {_^.n}; .bump_ {@n (_^.n + 1);}];",
|
|
1027
|
+
"; .tally2 (Tally.bump_ ());",
|
|
1028
|
+
"; [tally2.read(), (tally2.bump_ ()).n, Tally.n]",
|
|
1029
|
+
"# [2, 3, 1]",
|
|
1030
|
+
"",
|
|
1031
|
+
"`The receiver keeps the authority its method was granted. A non-mutating method",
|
|
1032
|
+
"that calls a mutator through it gets a functional update, and a mutating method",
|
|
1033
|
+
"reached through an immutable handle writes only its own copy.`",
|
|
1034
|
+
"; .Ticker [.k 0; .bump_ {@k (k + 1);}; .sneak {(_^.bump_ ()).k}; .twice_ {_^.bump_ (); _^.bump_ ();}];",
|
|
1035
|
+
"; [Ticker.sneak(), (Ticker.twice_ ()).k, Ticker.k]",
|
|
1036
|
+
"# [1, 2, 0]",
|
|
1037
|
+
"",
|
|
1038
|
+
"`A block nested in a method counts its carets lexically, so the method's",
|
|
1039
|
+
"receiver is one caret further out.`",
|
|
1040
|
+
"; .Outer [.k 1; .ks {[1, 2] & {_^^.k}}];",
|
|
1041
|
+
"; .Inner [.^ Outer; .k 5];",
|
|
1042
|
+
"; [Outer.ks(), Inner.ks()]",
|
|
1043
|
+
"# [[1, 1], [5, 5]]",
|
|
1044
|
+
"",
|
|
999
1045
|
].join("\n"),
|
|
1000
1046
|
],
|
|
1001
1047
|
[
|
|
@@ -3257,7 +3303,9 @@ export const HC_SOURCES = new Map([
|
|
|
3257
3303
|
"You can reach past the argument to the enclosing lexical scope (one level above)",
|
|
3258
3304
|
"using the `_^` identifier. It is not a `super` reference: it names the scope the",
|
|
3259
3305
|
"closure was written in, not a declared parent, and each caret is one more",
|
|
3260
|
-
"lexical scope out regardless of how the closure was called.",
|
|
3306
|
+
"lexical scope out regardless of how the closure was called. A method is written",
|
|
3307
|
+
"in its aggregate, so in a method that scope is the receiver the call is bound",
|
|
3308
|
+
"to, which may be a copy or a descendant of the aggregate.",
|
|
3261
3309
|
"```",
|
|
3262
3310
|
"; .print-arg { var };",
|
|
3263
3311
|
"; .print-parent { _^.var };",
|
|
@@ -236,10 +236,7 @@ export class EvaluationScope {
|
|
|
236
236
|
const forwarded = receiverState !== undefined &&
|
|
237
237
|
receiverState === enclosing?.receiverState;
|
|
238
238
|
if (receiverState && !forwarded) {
|
|
239
|
-
|
|
240
|
-
? new FrameHandle(receiverState.receiver, receiverState.mutable, receiverState.copyOnWrite, receiverState.lexicalContext)
|
|
241
|
-
: receiverState.receiver;
|
|
242
|
-
lookupFrames.push(receiverLookup);
|
|
239
|
+
lookupFrames.push(EvaluationScope.receiverLayer(receiverState));
|
|
243
240
|
}
|
|
244
241
|
if (closure)
|
|
245
242
|
lookupFrames.push(closure);
|
|
@@ -388,11 +385,39 @@ export class EvaluationScope {
|
|
|
388
385
|
lexicalAt(level) {
|
|
389
386
|
if (level <= 0)
|
|
390
387
|
return this.lexicalTarget;
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
388
|
+
const inner = this.outward(level - 1);
|
|
389
|
+
// A method's body is written in its aggregate, and a call binds it to a
|
|
390
|
+
// receiver: the aggregate itself, an instance copy of it, or a declared
|
|
391
|
+
// descendant. The level that reaches the scope the method was written in
|
|
392
|
+
// reaches that receiver instead, so the caret count stays lexical while a
|
|
393
|
+
// copy or a descendant reads its own fields rather than its source's.
|
|
394
|
+
const receiverState = inner?.methodReceiverState();
|
|
395
|
+
if (receiverState)
|
|
396
|
+
return EvaluationScope.receiverLayer(receiverState);
|
|
397
|
+
return inner?.enclosing?.lexicalTarget;
|
|
398
|
+
}
|
|
399
|
+
/** The scope `steps` enclosing scopes out from this one. */
|
|
400
|
+
outward(steps) {
|
|
401
|
+
return steps <= 0 ? this : this.enclosing?.outward(steps - 1);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* The receiver state this scope's call bound, when this scope is a method
|
|
405
|
+
* body rather than a block nested in one, which runs with the receiver state
|
|
406
|
+
* its method forwarded.
|
|
407
|
+
*/
|
|
408
|
+
methodReceiverState() {
|
|
409
|
+
const state = this.receiverState;
|
|
410
|
+
return state && state !== this.enclosing?.receiverState ? state : undefined;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* The receiver as a method call reads it: through a handle carrying the
|
|
414
|
+
* call's mutability and copy provenance when the read recorded a scope, so
|
|
415
|
+
* lookup through it reaches the receiver and its declared parents only.
|
|
416
|
+
*/
|
|
417
|
+
static receiverLayer(state) {
|
|
418
|
+
return state.lexicalContext
|
|
419
|
+
? new FrameHandle(state.receiver, state.mutable, state.copyOnWrite, state.lexicalContext)
|
|
420
|
+
: state.receiver;
|
|
396
421
|
}
|
|
397
422
|
/** Copies this scope's lookup layers with additions that are not present. */
|
|
398
423
|
appended(...additions) {
|
|
@@ -134,6 +134,14 @@ export class FrameSymbol extends FrameAtom {
|
|
|
134
134
|
this.isReceiverPathValue(receiver, value, origin)) {
|
|
135
135
|
return new BoundMethod(resolved, receiver, receiverState.mutable, methodEffect(this.data), receiverState.copyOnWrite, receiverState.lexicalContext);
|
|
136
136
|
}
|
|
137
|
+
// A method read by dot from a value no name holds binds to that value
|
|
138
|
+
// as a name would, immutably: it may still be shared, so a mutating
|
|
139
|
+
// method answers a functional update rather than writing it.
|
|
140
|
+
if (resolved instanceof FrameLazy && this.is.address === true &&
|
|
141
|
+
!(context instanceof FrameHandle) && context.ownsIdentity() &&
|
|
142
|
+
this.isReceiverPathValue(context, value, origin)) {
|
|
143
|
+
return new BoundMethod(resolved, context, false, methodEffect(this.data));
|
|
144
|
+
}
|
|
137
145
|
const copyOnWrite = context instanceof FrameHandle
|
|
138
146
|
? context.copyOnWriteScope() ?? receiverState?.copyOnWrite
|
|
139
147
|
: receiverState?.copyOnWrite;
|
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.
|
|
1
|
+
export const VERSION = "0.23.1";
|