This is what I thought is going on but it can’t be true:
I thought the conditions (red circles with numbers) that are surrounding the OR function need to have at leas one true.
so for example, either condition 1 or 2 need to be true in order to show rows that the true condition is true for. And if the condition 1 is true, it wont even check if the condition 2 is true or not, it won’t matter. It will just move on to the next condition.
In this example the next is another set of conditions: 3 and 4. The same goes for them, but between 1 and 2, and 3 and 4 is AND function. And AND function outputs true only if both sets of conditions output true.
Therefore
Set 1 (condition 1 & 2) = true
AND = true
Set 2 (condition 3 & 4) = true
but if:
Set 1 (condition 1 & 2) = true
AND = false
Set 2 (condition 3 & 4) = false
Now when we come to the next set and the next AND function, does that AND function require this entire thing… Set 1 (condition 1 & 2) = true AND = true Set 2 (condition 3 & 4) = true
…to be true and the next set of conditions (5 & 6) to be true. Or how does it work?
If the condition 9 is false, it won’t show any tasks at all no matter if everything before is true?
I’m sure someone can explain this to me in very simple terms but I can’t figure it out, I just wan to know how a program would go trough this step by step. I would appreciate it very much.
That is a good observation, I didn’t think about parentheses, but if I put it there it gives an error “missing close parenthesis” .
So the formula itself works fine, but I have trouble understanding it because the number 9 should be false for a lot of rows but they still show up. So how do they show up if the expression/condition (I don’t know how to call it) is outputs false and it’s right after the AND function. So My guess is that both 9 and the set of 7 and 8 need to output True for a row to be shown.
I am new to coda.io, but have some (just a littlebit) experience with programming in general. Going after the parentheses was my first idea, simply by experience, those things are so easy to overlook.
My best suggestion for you is to first copy the entire formula, and paste it in a texteditor. Then start by adding one layer at a time to the formula, making each step work, one by one, until you managed to fix the entire formula.
By first hand, your formula does seem slightly complicated, so doing it this way may help both in understanding, and also to troubleshoot for errors.
In simple basic terms:
AND → Both criterias must be met, otherwise it gives false.
OR → One or the other or both must be met, otherwise it gives false.
When you look closely in each filter pair that you group together with the logical operator OR / AND, I believe you will manage to see how it goes. This way, checking your filterpair one by one, you will see weather or not you got the logic correct in your formula.
Is there something that leads you to believe the formula is not working as expected? From glancing it seems correct.
What you are probably looking for is the associativity of operators in CFL, i.e. whether an expression like a AND b AND b is parsed as (a AND b) AND c, or as a AND (b AND c). The former is called left-associative, the latter is right-associative. I would imagine that CFL, like most other established programming grammars, uses left-associativity. In any case, it shouldn’t matter at all since both are equivalent. The only case it would matter is if you were depending on a, b, and c to be evaluated in some specific order, in which case you shouldn’t.
This should be the exact replica of my filter formula but in a simpler format.
There should be 3 bigger sets of conditions: a - d, e - g, h - i and j
Is that right? If it is, now everything makes sense. Thank you!
Hey — without reading too much here’s the overall answer on the associativity of operators.
AND — it’s like multiplication (actually it’s called logical multiplication). Just like 0x0=0, 0x1=0, 1x0=0, and only 1x1=1, AND is only true if both are true.
OR — it’s called logical addition. Only 0+0=0, otherwise 1+0=1, 0+1=1, and logically 1+1 also gives 1.
The order of operation applies just the same way as with arithmetic multiplication and addition. Unless there are brackets, AND is evaluated first, OR second:
a AND b OR c AND d
equals
(a AND b) OR (c AND d)
There’s also short-circuiting:
a AND b AND c AND d... will stop calculating as soon as it finds the first false. Analogically, a OR b OR c OR d will stop calculating as soon as it finds the first true.|
P.P.S. Wait, the formula in the original post looks a lot like something in my starter template (:
P.S. Each of the abc etc can be a boolean expression on its own.
Also when unsure, use brackets ().
a OR b AND c OR d AND e AND f
Let’s see if I get this right: It would calculate whether…
b AND c = true
d AND e = true
e AND f = true
Then it if it’s all true, it would calculate OR operators:
a OR b = true
c OR d = true ← This is confusing because it would make more sense if it checked whether instead of c it checked everything that is in brackets before it, and if that’s false then check if d is true. ← If this is true, then how would you type (a OR b) AND c) OR (d AND e) ADN f without any brackets
Yes, you use brackets to control the order of operations
Here’s the full documentation for JS. Coda is written in JS so it follows pretty much the same order (it’s only that there are fewer operators in Coda, e.g. no bitwise operators)
Here you can learn that e.g. equality has precedence over logical operators, i.e.
a = b AND c = d is evaluated as (a = b) AND (c = d), not a = (b AND c) = d