# Precedence of yield operator

Bruno Jouhier bjouhier at gmail.com
Fri Jun 14 12:40:31 PDT 2013

```The current precedence looks natural to me for a yield but less when yield
is used as an await keyword.  That's why I proposed to handle it with a
different keyword rather than by changing yield's precedence. Await would
have been a good candidate but it is not reserved.

Anyway, I don't want to make a big fuss about it. That's just something I
noticed while writing examples of async code with generators. Adding the
parentheses is not such a big deal.

2013/6/14 Brendan Eich <brendan at mozilla.com>

> Bruno Jouhier 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());
>>
>
> That's actually a hard case, IMHO -- and "hard cases make bad law".
>
> Many programmers would rather have the extra parens for uncertain cases
> (C's misplaced bitwise-logical and shift operators, vs.
> equality/relational; anything novel such as yield).
>
> But the real reason for yield being low precedence is to avoid precedence
> inversion. Consider if yield could be high-precedence, say a unary operator
> like delete:
>
> let x = yield a + b;
>
> Oops, many people would want that to be equivalent to
>
> let x = yield (a + b);
>
> but if yield is at delete's precence level, it's rather:
>
> let x = (yield a) + b;
>
> Which is the rare ("hard", from law school) case.
>
> For commutative operators such as +, over-parenthesizing is better again,
> because
>
> let x = b + (yield a);
>
> and
>
> let x = (yield a) + b;
>
> ignoring order of effects in shared mutable store, and ignoring floating
> point non-determinism, are equivalent.
>
> /be
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130614/bacebf27/attachment.html>
```