Precedence of yield operator

Tab Atkins Jr. jackalmage at gmail.com
Fri Jun 14 08:21:20 PDT 2013


On Fri, Jun 14, 2013 at 5:12 PM, Bruno Jouhier <bjouhier at gmail.com> wrote:
> While playing with my little async/await library, I noticed that I was often
> forced to parenthesize yield expressions as (yield exp) because of the low
> precedence of the yield operator. Typical patterns are:
>
> var foo = (yield a()) + (yield b()) + (yield c());
> if ((yield a()) && cond2 ...) ...
>
> Looks more LISPish than JSish to me.
>
> The low precedence plays well with yield _statements_, as it lets you write
>   yield a + b;
> very much like you would write
>   return a + b;
>
> But it does not play as well with yield _expressions_.
>
> The only solutions I can think of would be to have a different keyword for
> yield _expressions_ (await?) with the same precedence as other unary
> operators.
>
> Anyway, this is only a small annoyance and I know it's getting late into the
> game. But I thought I'd raise the issue anyway.

Using generators for async is a clever hack, but it's just a hack.  A
proper solution will need a new keyword anyway (most languages seem to
use "await" or something similar), which can get the better
precedence.

~TJ


More information about the es-discuss mailing list