yield* desugaring

Andy Wingo wingo at igalia.com
Thu May 2 12:24:17 PDT 2013


Greets,

Thanks for the kind words!  And thanks also for the new iteration
proposal; it looks great to my ignorant eyes.  I'll probably take a look
at for-of next.

On Thu 02 May 2013 20:07, David Herman <dherman at mozilla.com> writes:

>> IMHO yield* should be specified to return the result object as-is,
>> without re-boxing.  This precludes a straightforward desugaring, but it
>> is probably more flexible.
>
> This is an interesting question. I agree that the intuition of yield* is
> chaining together continuation frames and therefore "just pass on
> through" seems like the Right Thing. It's only maybe slightly
> disconcerting that yield* therefore actually gives you additional power
> that you can't otherwise express locally (i.e., you have to transform
> the entire containing generator function). But I'm with you, this seems
> right to me.

I was working on this today and thought better of my original proposal.
It would be nice to assume that calling next() on a generator returns a
{ value, done } object, and that is not necessarily the case if we pass
on the result from calling some other iterator:

>      let next = send ? g.send(received) : g.throw(received);

Here "g" might not be a generator object -- though we could specify that
it is [*] -- and "next" might not have the { value, done } form.  It might
not even be an object, in which case getting the "value" would fail at
an even greater distance from the original error.

This is a very small point in the scheme of things, but it seemed to me
that desugaring as "yield next.value" was probably less confusing to
users.  WDYT?

Regards,

Andy

[*] If we specify that "g" is a generator object, then this question is
moot: the identity of the result of "g.send(receiver)" is not visible.


More information about the es-discuss mailing list