I just debugged a problem which proved to be that "and" evaluated both arguments before checking whether either was false. That's fine, not all languages handle x = (will_return_true() || loop_forever()) ? "win" : "lose"
in short circuit fashion.
Is there prior art on a symmetric equivalent?
Interpret x = (loop_forever() || will_return_true()) ? "win" : "lose"
as successfully as the conventional way around.
Short circuit evaluation on and
, or
is essentially control flow wrapped in syntax. The control flow I'm looking for would amount to:
- Start evaluating both arguments
- When either completes, see if the other is still necessary
- Kill off the other and return immediately when possible
Also of interest would be any language which takes this approach to argument evaluation without the above syntax. I'm tagging as functional-programming because the above wouldn't play nicely with side effects, especially if it's non-deterministic which branch completes first.
I don't think this is equivalent to prolog style back tracking but could probably be persuaded otherwise.
join()
, or two Futures and ajoin()
, or something based on streams andselect()
. – 9000 Sep 13 '17 at 0:35