Rethink operator precedence #128
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I don't like the current precedence of operations in haku (and other languages, for that matter.) I think they result in lots of unnecessary parentheses when doing math, and frankly, for writing math operations, I'd prefer that they always went from left to right, rather than "multiplications first, additions later."
Therefore, I want to flatten the precedence table a bit. Current precedence:
New precedence (including new operators #44 #126 #127)
Basically: arithmetic goes from left to right. Comparisons still have lower precedence, because that way is more convenient.
This still makes passing arguments to functions really annoying. Therefore, whitespace around operators should become significant.
+ - * / .
: If no space on either side, precedence is higher than(function call)
. If there is space on either side, precedence is lower than(function call)
. Unbalanced whitespace is an error.-
: If space on the left only, treat as prefix.|
: Unaffected by these rules, because it goes tightly into interaction with function calls. Precedence always lower than function calls, and is insensitive to whitespace.Additionally, in this configuration it should be possible to have a newline before an operator, to carry the expression over to the next line. This should work with all operators except function calls.
.
dot operator #127