Operators ||= and &&=
david-sarah at jacaranda.org
Wed May 6 17:23:18 PDT 2009
Ash Berlin wrote:
>> I don't think ||= and ??= are very difficult to define clearly.
>> Perhaps just a line each in terms of the expanded syntax. I don't
>> think they would add much bloat to engines. Perhaps just better to add
>> them both and move on to discussing classes, lambdas, or processes.
> a ||= b;
> a = a || b;
Note that in general, 'a op= b' is *not* equivalent to 'a = a op b',
the main issue being that 'a op= b' evaluates 'a' once, and 'a = a op b'
evaluates it twice.
It is difficult, perhaps impossible, to give a correct expansion of
the compound assignment operators in terms of the corresponding
non-assigning operator, because there isn't (AFAIK) any way
to preserve an evaluated LeftHandSideExpression, without applying
GetValue to it, while the right-hand-side is being evaluated. So
these operators have to be treated as primitive.
David-Sarah Hopwood ⚥
More information about the es-discuss