Escaping static context #82
Replies: 4 comments
-
Pondering this further, if closure is considered aliasing (and if Something makes me think Jessie was designed this way. Thanks, |
Beta Was this translation helpful? Give feedback.
-
Oh, okay now I think I got it. Cycles can exist due to Map, Set and friends, which are mutable collections, even if literals cannot be used as such. So this "API surface" concept exists because the only use of escaping object, function, and array literals is in defining APIs. Collections are a separate concern from that, and already have a defensive API. Pardon my ramblings... Still chewing on this. |
Beta Was this translation helpful? Give feedback.
-
If you don't mind, I find the sequence of aha's informative. Please keep rambling! JavaScript has several places where mutable state lurks, primarily:
Jessie has the first two (e.g., I say "mostly" because Jessie does allow mutable property updates for initialization only, of objects that are not yet otherwise reachable. That's the intention anyway. The exact rules needed to realize this have not yet been precisely worked out, so these questions are timely. I am confused about your example: function makeRunningTotal() {
const totalArr = [0];
function add(addend) {
totalArr[0] += addend;
return def(totalArr[0]);
}
return def(add);
} Since |
Beta Was this translation helpful? Give feedback.
-
As for my example, I was trying to discern some conservative "no escape or aliasing without def" rules that don't require full data typing or semantic analysis, but it was all rather hand-wavy. |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a request for clarification:
I understand "aliasing" to mean assignment to another object (array element, variable, or object property). Clearly, some ways of "escape" are being used in a return or throw statement. Do these concepts include being closed over by a subfunction?
So is the following legal Jessie?
I don't read anything in the current document that directly says all mutable state is to be prevented, but I am unclear if the totalArr in the above can be used as a mutable state container, or if it needs to be a direct variable reference. Or further, if this pattern of mutation is simply not allowed (i.e. closure is considered a form of escape from the static context).
Thanks: I'm working up to an understanding of what Jessie really means,
Michael.
Beta Was this translation helpful? Give feedback.
All reactions