3 ms·
This is also the classic argument against reverse polish notation. Operator-first makes it harder to say the name of an operator in a sentence.
by throwaway173738 3y ago
This is also the classic argument against reverse polish notation. Operator-first makes it harder to say the name of an operator in a sentence.
- ajuc 3y agoReverse polish notation is operator last.
- eru 3y agoOperator first makes the sentence easier: '+ 2 3' becomes 'add 2 and 3' In any case, it's a silly objection.
- pxc 3y agoIt's an especially silly objection in the case of the command line, where prefix notation is already the norm anyway. + 2 3 is naturally how you'd write addition if addition were a standalone Unix command!
- jrockway 3y agoInfix operators are very weird, though. They come from math, where every elementary school student has to memorize "please excuse my dear aunt sally" to be able to answer a simple question like "what is 2³ + 4 ÷ 2". C copied this concept, and nobody really ever bothered to memorize C's operator precedence, so they just end up writing Lisp but with the operators in the middle. pow(2, 3) + (4/2). Note that some operators appear prefix instead of infix for no apparent reason. (You can't just remember what you learned in math class when writing a computer program, because now we have bitwise and, or, xor, left shift, right shift, equality, pointer dereferencing, assignment, logical and, or, modulo, pre-increment, post-increment, bitwise not, logical not, etc. So you have to learn it all again. And it's different for every language.) Put everything up front, and suddenly you don't have to think about this anymore. (+ (expt 2 3) (/ 4 2)). The computer just does what you say and there are no rules to memorize. Personally, I always use RPN calculators (dc is my favorite), because I don't trust the calculator to remember operator precedence. They usually do it right, but it's difficult to reason about. (The example would be "2 3 ^ 4 2 / + p" in dc.)
- vram22 3y ago>every elementary school student has to memorize "please excuse my dear aunt sally" In Indian schools it used to be BODMAS, for Brackets Of Division Multiplication Addition Subtraction, for operator precedence, for which our teachers told us the mnemonic was badmaash, meaning a scoundrel or a villain, in Hindi. Guaranteed to make kids remember it. :) Of, as in half or a quarter or ... of some other number.
- antonvs 3y ago> C copied this concept I think FORTRAN copied it first. Which makes sense, because of the original scientific target market for FORTRAN, represented in its name derived from “formula translating system”. Translating “a sufficiently rich mathematical language”, as Backus put it, was an explicit goal as early as 1954. C then (presumably) just followed the convention established by FORTRAN.
- somat 3y agoUnfortunately we will never get rpn taught in schools so it will always feel unnatural and weird to many people. what is unnatural is the complicated case specific precedence rules mid notation requires. rpn still has precedence rules but because they are simple it appears that there are none and because they are universal there is no confusion as to where any new operators fit in. I wonder if anybody has ever written a linguistic history of math notation and how it ended up the way it did.
- ajuc 3y agoMaybe it's just what I'm used to, but doing anything other than calculating the value of an expression with RPN seems hard to me. (x-3)(x+2)-8 > 2x^2+3 x^2-x-8 > 2x^2+3 x^2+x+8 < -3 x^2+x+11 < 0 vs x 3 - x 2 + * 8 - x x * 2 * 3 + > how would I simplify the expressions here? Maybe it's possible without transforming to infix but I can't do it.
- XorNot 3y agoYes but it cleanly separates code and data, and notably on an interactive shell makes editing a historical command much simpler site to cursor positioning.