3 ms·
Alternate formulation with hypothetical shift/reset (delimited continuation support) and blocks that return the same way functions do: mtime: function () {
by ericbb 15y ago
Alternate formulation with hypothetical shift/reset (delimited continuation support) and blocks that return the same way functions do:
mtime: function () {
return reset {
var mtime = shift (succeed) {
this.withFile ({ |f|
var mtime = this.mtimeFor (f);
if (mtime < new Date () - 1000) {
return "too old";
}
return succeed (mtime);
});
};
sys.print (mtime);
return "young enough";
};
},
The succeed function is a first class, indefinite-extent function equivalent to:
function (mtime) {
sys.print (mtime);
return "young enough";
}
It's the computation within the reset block that comes after the shift form is evaluated.
Calling it after returning from the method would not raise an exception.
Edit: Keep blocks with 'this' inheritance (I had originally used a standard closure).
- BrendanEich 15y agoDelimited continuations are not gonna happen. See http://wiki.ecmascript.org/doku.php?id=strawman:shallow_continuations http://wiki.ecmascript.org/doku.php?id=strawman:shallow_cont..., http://calculist.blogspot.com/2010/04/single-frame-continuations-for-harmony.html http://calculist.blogspot.com/2010/04/single-frame-continuat..., and http://calculist.org/blog/2011/12/14/why-coroutines-wont-work-on-the-web/ http://calculist.org/blog/2011/12/14/why-coroutines-wont-wor....
- ericbb 15y agoThanks for the links. It's neat to see such things being considered. My feeling is that such complicated language devices are out of place in JavaScript but it was fun to run the experiment. While I'm thinking about it... I wonder about the choice to overload/reuse the keyword 'return' in the blocks proposal. Any thought on using something else to emphasize the distinction in semantics? Edit: Nevermind. That would break the Tennent Correspondence Principle wouldn't it? Bad idea.