4 ms·
> I'm not sure I'd say that it can't be done. In some languages it could be implemented if the language itself supports optionals. So "bool ? x" could result in
by Someone 2y ago
> I'm not sure I'd say that it can't be done. In some languages it could be implemented if the language itself supports optionals. So "bool ? x" could result in an Optional<type(x)>, while "Optional<type(x)> : y" could be the typical implementation of value_or that is found on optionals.
It is tricky because, in
flag ? x : y;
exactly one of x and y gets evaluated.
So, flag ? x would have to evaluate flag first, and only evaluate x if that has a truthy value.
That can be tricky in many languages, for example if the programmer writes
(b ≠ 0) ? a ÷ b : 0;
You’d need lazy evaluation of arguments or something similar.
- Izkata 2y agoYou and GP are basically describing "bool && x" and "bool || y" (for the languages that return the value instead of strict booleans when evaluating && and ||)