A case for intransitive operator precedence (2019)

11 points by habibalamin


Internet_Janitor

I find this proposal deeply unconvincing.

APL-family languages tend to have a much larger collection of primitive operators than C-family languages. The example grammar makes a variety of arbitrary (if familiar) choices about relationships between operators. What is the elementary-school intution for the relative precedence of the addition operator and the tally operator, or the grade operator? There is none.

All programming language syntax and semantics must be taught and learned. Instead of hazily appealing to the familiarity of a notation optimized for writing polynomials (and hoping the programming language author made similar leaps of imagination to oneself), uniform operator precedence (whether polish, reverse-polish, or strictly RTL/LTR) offers a simple rule that is easy to explain and easy to implement. With a little practice, it’s perfectly natural to read and write, and avoids arbitrary design choices and memorization. Intransitive operator precedence may shave a handful of ambiguous constructions away from the possibility space of a C-like language, but it does nothing to simplify the description or implementation of the language.

LesleyLai

I like Carbon’s approach of treating precedence as intransitive and as a DAG https://github.com/carbon-language/carbon-lang/tree/8ad08e34e2b4da15c778ff5db60023123577b085/docs/design/expressions#precedence.

I am also doing something similar in my own experimental language with a modified Pratt parser.