revisiting "shift"

Peter van der Zee ecma at qfox.nl
Tue Apr 27 23:11:56 PDT 2010


On Tue, Apr 27, 2010 at 4:57 PM, David Herman <dherman at mozilla.com> wrote:

>
> Example:
>
>    function f() {
>        try {
>            for (let i = 0; i < K; i++) {
>                farble(i);
>                // suspend and return the activation
>                let received = shift (function(k) { return k });
>                print(received); // this will be 42
>            }
>        }
>        catch (e) { ... }
>    }
>
>    let k = f(); // starts running and return the suspended activation
>    ...
>    k.send(42); // resume suspended activation
>
>
It seems to me like the callback is unnecessary overhead. What happens if
you don't supply a function but another type, or none? Would 42 still be
"returned" by shift? Or is it actually the returned value in k, that gets a
send method augmented to it?
It'd be cleaner if it was just shift(), no argument, which returns a
callback bound to the continuation which can simply be called without
suffix:
function x(){
  let received = shift();
}
var y = x();
y(42);

But maybe I'm knifing an entire API here I don't know about :) Otherwise the
send method seems redundant.

- peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100428/59e42478/attachment.html>


More information about the es-discuss mailing list