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.

➡️ Stable 0.5x Programming Languages
3,397
Comments
20
Years Active
5
Top Authors
#8469
Topic ID

Activity Over Time

2007
4
2008
44
2009
48
2010
117
2011
81
2012
144
2013
167
2014
141
2015
137
2016
161
2017
228
2018
160
2019
229
2020
286
2021
317
2022
271
2023
247
2024
338
2025
270
2026
7

Keywords

DonHopkins REP PHP lang.org e.g www.cs LISP JavaScript cmu.edu MD precedence notation operator operators parentheses prefix multiplication expressions language math

Sample Comments

Arch-TK Jan 26, 2023 View on HN

It's a bit hard to parse it outside of languages like lisp because of infix.

krickle Feb 4, 2013 View on HN

I thought that was for infix expressions with order of operations?

baddox Feb 6, 2012 View on HN

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.

madcaptenor Oct 22, 2014 View on HN

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 ...)

ZoF Jul 13, 2015 View on HN

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.

wuschel Apr 8, 2021 View on HN

LISP-like languages have enforced operator precedence due to polish notation e.g. (+ (* a b) (+ c d))

ghettoimp Mar 16, 2019 View on HN

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.

sillysaurus2 Feb 4, 2014 View on HN

Infix math is only nice because you've been trained to believe it's nice.

rustybolt Jan 21, 2020 View on HN

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.