Hello hello!
Today we have an update for those of you who have crafted custom complex conditions or those of you who would like to get started and that find AND and OR not sufficient as operators. Today we are introducing: XOR, NOR and NAND!
Before I go any further, some of you might be wondering where NOT is. We haven’t implemented it this time, as it requires some very careful changes in Apilio, but rest assured that now that we’ve implemented these other 3 operators we have a better idea of how to proceed with NOT. I can’t say anything else at this point
How the logic operator XOR works
This has been implemented following Microsoft’s specification for XOR: https://support.microsoft.com/en-us/office/xor-function-1548d4c2-5e47-4f77-9a92-0533bba14f37
The operator XOR:
- results in TRUE when the number of TRUE conditions is odd
- results in FALSE when the number of TRUE conditions is even
So if you have three conditions (odd number) and all of them are true, XOR returns true. But if you only have two conditions (even number), then XOR returns false.
How the logic operator NOR works
NOR results in TRUE if all the conditions are false.
NOR(i_m_home, robin_is_home) returns true when nobody is at home.
NOR is just the opposite of the basic operator OR:
NOR() = NOT(OR())
How the logic operator NAND works
NAND results in TRUE if, and only if, at least one of the conditions is false.
NAND(watered_yesterday, rain_yesterday) will be true if either:
- the plants were watered yesterday and it didn’t rain
- it rained but the plant’s didn’t get watered
NAND is just the opposite of the basic operator AND:
NAND = NOT(AND())
But I really want the NOT operator
Good news is NOR and NAND work exactly like NOT() if only used with one element. So if you apply NOR to one condition, you’ll get the opposite, making these equivalent to NOT.
How to implement complex conditions
If you are just getting started, you want to have a look at the basic AND and OR operators in this previous article:
This article walks you through nested complex conditions, how to write them and gives you a couple of interesting examples.
I have questions! Doubts! Concerns! Requests!
Please put them below, we are happy to help!