yield syntax (diverging from: How would shallow generators compose with lambda?)
Neil Mix
nmix at pandora.com
Mon May 18 12:15:10 PDT 2009
On May 18, 2009, at 12:23 PM, Brendan Eich wrote:
> Making them mandatory is the issue. You can derive whatever comfort
> you want from 'em, but they are not required and we're not going to
> start requiring them for return, delete, or typeof. So mandating
> parentheses for yield is kind of wrong. Obviously the issue would go
> away if the precedence where the same as delete and typeof. Hence
> "kind of".
Ah, but delete and typeof are different in that they both *require* an
argument (terminology be damned, hopefully you understand what I mean
by that.) And return is different because it can't be used in an
expression. See my previous let x = yield-5; example -- let x =
typeof-5; is unambiguous.
I'm tempted to argue that yield should require an argument, and then
you could give it precedence equivalent to delete and typeof. But
that would make a statement like
yield x - 1;
utterly confusing.
Set aside for a moment the argument of *which* form of parenthesis for
a moment, and assume (yield E) wins for now. Could we redefine yield
so that it has two forms, a statement form and an expression form?
The statement form would be
yield E;
where E is optional. And the expression form would be
yield E
where E is required, and yield has precedence equivalent to delete and
typeof. Is that possible? Doing so would render any argument about
parenthesis moot, since they'd rarely be required, right?
More information about the es-discuss
mailing list