Yes, I brought it up (there under my “Páll Haraldsson” name, not my nickname), still writing my counterproposal (mostly justification, performance analysis) for opening a new issue on Github.
julia> hello() = begin print("Hello"); return false end # think of this as just some slow function without side-effects and the other fast
julia> world() = begin println(" world!"); return true end
julia> hello() & world();
Hello world!
Is this the semantics we want for bitwise & (that order, ignoring the side-effect of actually printing anything out)?
julia> if hello() && world()
println("This would be strange, would only happen if short-circuit was right to left..")
end
Hello
I’m looking at all options, than only “logical” && (left short-circuit), or bitwise & (seems to [must?] evaluate left, right, then the middle - the “bitwise and”).
E.g. the non-existing right short-circuit (or other possibilities…).
[Comparisons chaining, e.g. a() < b() < c() < d() … (currently) implies a() < b() && b() < c() && c() < d() …
All (or any) of the implied && could have been right-short-circuiting (or &), so you have exponentially many options just there.
I guess the semantics of chaining must imply one operator, we as language designers “choose” that one, but it could be my super-operator and
that can take many forms, allowing for any combination.]
Real “logical and” is associative, McCarty added short-circuit, conflating it with control flow.
Other options, that can be faster, are:
- right-short-circuit
- sometimes left sometimes right, for the same code, depending on data.
- maybe other options with even deeper implications… I’m working on that, to see if they lead to nowhere
I want the default to be maximally fast, or at least allow the implementation to consider all the above options and optimize statically for the best way if possible, dynamically if you have to.
I think I know what Julia does currently. And many C and C++ can (and cannot do… see my survey (already with some wrong answers - for Julia, in the context of if & is safe to substitute for &&, but not in C) at:
https://www.quora.com/and-and-or-Do-you-use-or-or-or-Is-faster-than-See-details-first-not-other-answers-I-also-want-beginners-to-answer-Similar
P.S. Did you know you can overload && and || in C++? One more reason to hate C++, as it disables short-circuiting and then brakes code. Who designed that, and why? This is I guess very rarely done, but I guess the optimizer needs to know, if done…