3 ms·
This is a simple expression. How about writing (1+2) * ((3 + 6) / (1+2)) in prefix notation without losing readability? When precedence is to be overridden, t
by tuxychandru 16y ago
This is a simple expression. How about writing (1+2) * ((3 + 6) / (1+2)) in prefix notation without losing readability?
When precedence is to be overridden, the infix form can be easily understood by anyone with basic knowledge of arithmetic. Prefix on the other hand can be confusing. This makes BigDecimal arithmetic in Java cumbersome compared to languages which allow operator overloading.
- vegai 16y ago1 2 + 3 6 + 1 2 + / * ;)
- jesusabdullah 16y agoprefix, not postfix: (* (+ 1 2) (/ (+ 3 6) (+ 1 2))) I was also skeptical regarding the readability of prefix notation vs. postfix for large problems. However, when I tried it, I actually found it easier to handle. For example, here's a very obnoxious heat transfer correlation that I typed in common lisp: ( * 4.364 (expt (1+ (expt (/ Gz 29.6) 2)) 1/6) (expt (1+ (expt (/ (/ Gz 19.04) (* (expt (1+ (expt (/ *Pr* 0.0207) 2/3)) 1/2) (expt (1+ (expt (/ Gz 29.6) 2)) 1/3))) 3/2)) 1/3 )) Versus, in infix it's more like: 4.364 * (1. + (Gz/29.6)**2)**(1/6) * (1 + ( Gz/19.4/( (1 + (Pr/0.0207)**(2/3) )**(1/2) * (1 + (Gz/29.6)**2 )**(1/3) ))**(2/3) )**(1/3) Now, I admit that my sense of whitespace is pretty inconsistent, but still: Here is a real case of a very annoyingly nested expression in both infix and prefix notation. While I think it would take quite a while for anyone to sort out what the Hell is going on for either of these regardless of experience (versus, say, rendered LaTeX), I would put forth the suggestion that the common lisp is actually easier to understand.