3 ms·
WTF is right-to-left evaluation's purpose? It breaks the most fundamental rules of arithmetic. As a human that has been taught those rules, I'd never come up wi
by dylan604 3y ago
WTF is right-to-left evaluation's purpose? It breaks the most fundamental rules of arithmetic. As a human that has been taught those rules, I'd never come up with 9 as an answer. Why did humans create a programming language that would?
- RodgerTheGreat 3y agoTraditional mathematical notation has precedence rules optimized for expressing polynomials. Programming languages- especially in the APL family- tend to have a richer collection of primitive verbs, and an "ideal" tower of binding precedence for all of them would be extremely complex, difficult to remember, and often unhelpful. Unform evaluation order is much easier to remember and extend (no special cases!) and becomes even more natural than PEMDAS with a little practice. The APL family is hardly unique in this approach to precedence: Smalltalk has uniform infix precedence, Forths are uniformly postfix (unless you get goofy with parsing words), Lisps are uniformly prefix.
- fiddlerwoaroof 3y agoIMO, infix operators in math are a historical relic of function notation being developed after the basic operators became widespread. I’ve always thought uniform prefix notation is ideal, whether it’s lisp-style (+ 1 x y) or the more common +(1, x, y)
- fiddlerwoaroof 3y agoI remember having this question when learning J, and they pointed out that it makes the = operator behave correctly. After: a = 1 + 2 One expects `a` to equal 3. If you have a uniform left to right evaluation order, it will equal 1 and then the whole expression will be set to 3, so you’d need to write this to get the intuitive result: a = (1 + 2)