Feather2 / documentation / Precedence.md
Precedence
Precedence determines the order that parts of an expression are evaluated. Consider :
a + b * c
In general, expressions are not evaluated left-to-right. Instead, each operator is ordered by its precedence. If two operators have the same precedence, then they are performed left-to-right.
In the example above * is performed before +, so these are identical :
a + b * c
a + (b * c)
- Parentheses
- Postfix Unary operators
++ -- - Fields/Function/method calls, including
withandapply. Array access[] - Prefix Unary Operators
+ - ! ++ -- as as?- Power :
^ - Multiplicative :
* / ~/ % - Additive
+ - .. => - Infix function calls e.g.
a myFunction b - Elvis
?: is !is- Comparisons
< > <= >= - Equality
== != === !== - Conjunction
&& - Disjunction
|| - Assignments
= += -= *= /= ~/= %=
AFAIK, this ordering is identical to Kotlin.
If you have Commands enabled, then |> (append redirect) is in the Comparison group
(together with > and <, which perform redirects).
And | (pipe) is Equality group.
PS. I find the terminology confusing. Consider the phrase multiplicative operations have a higher precedence than
additive. Yes, they are higher in the list, but the number is lower!
To overcome my confusion, I remind myself that 1 is first (i.e. these are ordinals, not cardinals).
If you mix && and ||, I recommend that you ALWAYS include parentheses,
even when it isn't strictly needed.