2 ms·
I don't think they're really the same thing. Arithmetic precedence comes from the meaning of the operators themselves while the other layers of grammatical prec
by stormbrew 12y ago
I don't think they're really the same thing. Arithmetic precedence comes from the meaning of the operators themselves while the other layers of grammatical precedence simply provide consistent structure. The reason this is a problem when the operators can overload is that the structural aspects of the operators may no longer apply to their meaning. See for example the iostream operators << and >> in C++, which actually have a very awkward precedence that forces you to parenthesize things in unexpected ways sometimes.
- vorg 12y agoOperators were first introduced in programming languages for arithmetic, .e.g. Fortran, but they've evolved beyond that. As an example, Scala gives precedence to operators based on the first token in the op, so e.g. *>> has higher precedence than +~< because * "beats" + Golang treats * / and & as having the same precedence, and ditto with + - and |