Speaking of short-circuiting, one slightly complicating issue I can think of is the following.
For example, the following two similar snippets are crucially different:
A:
var b = false
b = foo.frobnicate(by: x) || b
b = foo.frobnicate(by: y) || b
b = foo.frobnicate(by: z) || b
B:
var b = false
b = b || foo.frobnicate(by: x)
b = b || foo.frobnicate(by: y)
b = b || foo.frobnicate(by: z)
(A frobnicates foo tree times using b to see if at least one of them returned true, while B doesn't frobnicate foo at all, and is probably a programmer's error. EDIT: Correction, B frobnicates foo at least once, ie until and including the first that returns true, whereas A always frobnicates foo three times, using b
to know if at least one of those three mutating calls returned true. TLDR: Both variants are useful, but clearly different.)
But a hypothetical ||=
var b = false
b ||= foo.frobnicate(by: x)
b ||= foo.frobnicate(by: y)
b ||= foo.frobnicate(by: z)
would only be equivalent to one of them, which one?
And which corresponding one would &&=
be equivalent to?
Would it be necessary and/or reasonable to have both variants of each operator?
&&=
and =&&
||=
and =||