New operator:
a ||= b
// equivalent to
a = a || b
Saves typing the left side twice.
Also only evaluates the right hand when necessary.
Should also support these usages:
a[b] ||= c
var/type/a
a ||= new
See how other languages do it:
C#
PHP
ID:2571455
May 14 2020, 10:03 pm
|
|||||||
Resolved
| |||||||
(Couldn't find an existing request, but I remember this being brought up before)
New operator: a ||= b Saves typing the left side twice. Also only evaluates the right hand when necessary. Should also support these usages: a[b] ||= c See how other languages do it: C# PHP |
May 15 2020, 2:25 am
|
|
+1, ALL THE LOGIC /o/
|
Yeah, this has kinda been on my mind a while as well. Consider it on the list for 514.
|
This is implemented for BYOND 514. The issue will be closed when the first beta is released.
The way this operator works is that the LHS is evaluated only once, so if it's a complex expression like L[i++] then the increment to i only happens once and you'll still be at the same list index if an assignment happens. The RHS is only evaluated if the LHS is true or false, depending on which operator you use. That is, for the ||= operator the RHS is ignored if the LHS is true; for the &&= operator the RHS is ignored if the LHS is false. |