Operator Precedence Notation
The cluster discusses operator precedence, associativity, and parsing challenges in infix notation versus prefix or postfix alternatives like Lisp's Polish notation, debating their naturalness and necessity for omitting parentheses.
Activity Over Time
Top Contributors
Keywords
Sample Comments
It's a bit hard to parse it outside of languages like lisp because of infix.
I thought that was for infix expressions with order of operations?
It's interesting to think that the whole notion of associativity and order of operations only exists because for some reason humans seem to find infix notation more "natural" for binary (or fixed arity) operators than more easily parseable and less ambiguous alternatives like prefix.
It's basically declaring operator precedence - saying "we're going to write things this way so we don't need so many parentheses". It's fairly analogous to writing sin^2 x for (sin x)^2, a notation which the intended audience is probably used to. (Although that notation creates its own trouble when you have sin^(-1) x ...)
Cool stuff!I'm curious why they chose to have expressions evaluated in right-associative order.... Basically why is operator precedence equivalent?Was it done because it was easier to code? Don't understand why this would be of significant difficulty.Won't this complete diversion from accepted notation hinder adoption?(not intending to imply they are aiming for widespread adoption)Could anyone who would use the app for an actual purpose chime in here?Totally unders
I'm the author of the post.With regard to operator precedence, my position may be closer to yours than you think. In the post I linked to about intransitive operator precedence (https://blog.adamant-lang.org/2019/operator-precedence/) I describe what I want. Basically, I think basic order of operations like `*` before `+` and associativity are important.
LISP-like languages have enforced operator precedence due to polish notation e.g. (+ (* a b) (+ c d))
Yup. In addition to ignoring the usual Lisp convention for associative operators, I think the article muddies the waters here by using words like "add" and "mul" in all of the non-infix examples, making them unnecessarily verbose. After using prefix notation for years, it seems very natural for pattern recognition and formula manipulation. Never having to think about precedence and associativity is really nice.
Infix math is only nice because you've been trained to believe it's nice.
Infix notation is closer to natural language, but it's only easier to read for simple expressions. You really have to know the precedence and associativity of each and every operator that is used to make sense of an expression.