• @Robin, I am attempting to report a parsing error, not a semantic error, and “while (0,0);” is a minimal reproduction. It is not intended to be a full, useful program; just the shortest and simplest snippet I can concoct that triggers the error, to assist with debugging. I did also explain what real examples would look like and why I care.

    I apologise for not including the link https://tc39.es/ecma262/multipage/ecmasc­ript-language-statements-and-declaration­s.html#sec-while-statement ; I truly didn't think it was necessary, because I thought everyone here would know what the comma operator is and does. Mea culpa.

    In any case, the standard, at that link, says this:

    Syntax
    WhileStatement[Yield, Await, Return] :
    while ( Expression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return]

    (and similarly for for statements, which are also affected by the bug).

    I don't really understand your point about truthiness. “x = costlyAccessor(i++), p(x.a, x.b)” returns the value of p(…), not the value of x. Per https://tc39.es/ecma262/multipage/ecmasc­ript-language-expressions.html#sec-comma­-operator-runtime-semantics-evaluation :

    13.16.1 Runtime Semantics: Evaluation
    Expression : Expression , AssignmentExpression

    1. Let lref be the result of evaluating Expression.
    2. Perform ? GetValue(lref).
    3. Let rref be the result of evaluating AssignmentExpression.
    4. Return ? GetValue(rref).

    In short, it does the same thing as in every other language in the C family, evaluating the value on the left, then evaluating and returning the value on the right. The use in loop conditions is generally consider to be the principal motivation for the existence of the operator, since elsewhere you can usually accomplish the same thing with some unpacking and a semicolon. Admittedly it is more commonly used in for loops than in while loops, but again, I was seeking the easiest example to debug the grammar on.

  • Sat 2021.10.16

    Thank you for posting that link @user135362 allowing us all to be on the same page. It eliminates the reader's possible confusion as to which reference is being used. The number of times a reference has been made to inacurate document detail, or an in process document constantly changing.

    The references I mentioned indicate a conditional expression to be evaluated within the while, while that comma operator contains both a statement expression as well. So should the statement expression also be evaluated as a conditional as in the reference example shown?

    As you pointed, I've only ever seen that in use to separate a list of increment operators inside the end of a for loop, and I have to agree with @allObjects that it adds too much confusion when not quickly readable/understandable by the onlooker.

    Another 'gotcha' is that it wouldn't be possible to insert Espruino's WebIDE editor side debugger statement at that point in order to single step debug. (didn't test that though)

    Also, if we keep expanding our expectations, feature creep will eventually not leave enough RAM for us to play!

    http://www.espruino.com/Features

About