yield syntax (diverging from: How would shallow generators compose with lambda?)
david-sarah at jacaranda.org
Fri May 15 19:16:40 PDT 2009
Brendan Eich wrote:
> On May 14, 2009, at 5:13 PM, David-Sarah Hopwood wrote:
>> Brendan Eich wrote:
>>> On May 14, 2009, at 1:14 PM, Neil Mix wrote:
>>>> I have this idea that it would be better for yield expressions to look
>>>> like function calls: 'yield' '(' expression? ')'. [...]
>>> The syntax could work but we need to reserve yield contextually.
>>> It can't be a user-defined function name and a built-in function. The
>>> compiler must unambiguously know that yield (the built-in) is being
>>> called in order to make the enclosing function a generator.
>>> This is reason enough in my view to keep yield a prefix operator and
>>> reserve it.
>> But that doesn't help: the argument to yield is an arbitrary expression,
>> so 'yield (foo)' could be either a function call or a yield-expression.
>> That means that this approach can at best be no simpler to implement or
>> specify than the function call syntax.
> Were you responding to Neil instead of me?
I was responding to "This is reason enough in my view to keep yield a
prefix operator and reserve it".
My point was that the example of 'yield (foo)' (that is, yield as a
prefix operator applied to the expression '(foo)') shows that the prefix
operator syntax cannot possibly be easier to specify than the function
call syntax -- contrary to what you appeared to be arguing above.
In fact I think it is much harder to do correctly.
>> With the function call syntax, it would be sufficient to keep the
>> existing ES5 grammar for function calls, and then check after parsing
>> whether a MemberExpression or CallExpression followed by Arguments is
>> the string "yield". With the operator syntax, it's more complicated
>> than that because there are more syntactic contexts to consider.
> Yes, but it's not that complicated. SpiderMonkey and Rhino do it. Code
> size burden is in the noise.
Hmm. SpiderMonkey and Rhino use ad-hoc parsers. Show me an unambiguous
grammar for the prefix yield operator, and then I'll concede the point :-)
David-Sarah Hopwood ⚥
More information about the es-discuss