On 3 Jul 2015 at 11:45, Bjorn Reese wrote:
Out of interest, what do you think of my free function ternary logic programming:
So far, the discussion has focussed on how the ternary operators should behave in if-statements. In that case, I tend to agree with Lee's enum and switch suggestion, which also extends well into multi-variate logic.
My tribool allows switch and enum if you want it. It's just it requires a bit more typing, and I dislike typing :)
If we want to use the ternary logic in if-statements, then we should address composite conditions. For instance, what should the following evaluate to?
if (Empty && Value) {}
if (Empty && Error) {}
if (Empty && Empty) {}
The question really boils done to what influence Empty has. Do we want it to influence the results, or should it act like a "don't care" value?
That's exactly the nub of the problem. Which ought to be dominant over the other, empty or errored? i.e. is it: Empty < Errored < Valued i.e. Empty && Errored = Empty or: Errored < Empty < Valued i.e. Empty && Errored = Errored. Me personally, I chose the Kleene logic because I felt Empty is like NaN in floating point, so it is always dominant. And I suppose we can retain that, even with Errored => False, Empty => Unknown, with the appropriate truth tables. The tricky part is which is the best design? I'm not sure if that's answerable from a purely top down approach. Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/