I made a simple code change, giving _ the same precedence as ^. With this change, code like A=B_"km"/C_"h" works as expected.Thomas Okken wrote: ↑Tue Aug 16, 2022 4:23 pmThe underscore is a multiplicative operator, so it has the same precedence as * and /, that's why the parentheses are needed in your example. I should mention that in the documentation.
This change will be in the next release.
It would be even better if _ had even higher precedence, higher than ^, although this change will do what's expected in most cases, i.e. 10_"km"^2 will evaluate to 100_km^2 because in the HP equation language, exponentiation is left-associative. So I'm not completely sure if it's a problem to have _ and ^ at the same level of precedence.
Changing the precedence is tricky because the Plus42 parser is completely hand-written, that is, I didn't use a parser generator, and so changes to the grammar require non-trivial code changes, and I don't deal with parser logic often, so it tends to give me a headache. But if anyone can come up with examples of why _ should have higher precedence than ^, I will take care of it.