+ 1 2
fundamentally different from: 1 2 +
? You just look for the operator on the other side of arguments.I know both prefix, postfix and "crazy infix" (J, some APL) languages and I really don't see a qualitative difference. Of course, after you overcome the initial hurdle and get used to the notation.
EDIT: ok, J/K/APL are a special case and I shouldn't mention them.
Can you parse the following easily?
c_z x * s_z y * s_y * c_y z * + c_x * c_z y * s_z x * - s_x * - d_z =
Compare that to the infix form:
d_z = c_x * (c_y * z + s_y * (s_z * y + c_z * x)) - s_x * (c_z * y - s_z * x)
With infix, the operator sits between its operands, so you can easily see what expression makes up the first operand, and which makes up the second: you just look to its left and its right. Postfix, however, requires you to read the entire expression, because the operator doesn't show which operands it has, they're just whatever the last two were, and those last two might themselves be complex expressions. This gets worse the longer the total length of the expression.
Postfix also suffers from not making it clear how many operands a given operator takes. With infix this is always clear.
I like postfix languages for their simplicity, but I refuse to pretend they are as easy to read as infix languages.
(example was taken from https://en.wikipedia.org/wiki/3D_projection#Perspective_proj...)
Anyway, let's try doing something with your postfix example (I hope it displays alright; also, I think you made a mistake in your translation to postfix, but I left it as it is):
c_z x *
s_z y *
s_y *
c_y z *
+
c_x *
c_z y *
s_z x *
-
s_x *
-
d_z =
Now, this is much more readable than unformatted infix version you give and that's before factoring this into smaller parts. I didn't read that much of Forth, but I'm 97% sure that it would be factored into 3 or 4 words, I think. And it also has an advantage that you read the operation in order they're going to be executed, while with infix you need to read the entire expression to know which computation occurs first.Of course, it's only more readable for me, with my particular background knowledge and habits; I'm not saying this is or should be the same for anyone else. But, if there are people who see one form as more readable and people who see the other form as more readable, then I think that's a solid argument in favor of both forms not being drastically, qualitatively different.
The problems you point to are definitely real; it's true "the operator doesn't show which operands it has" by default (for example) and you need to go out of your way to show it. But infix notation has it's problems too, and you need to work around them as well. Like operator precedence, which is frankly a terrible idea.
> Postfix also suffers from not making it clear how many operands a given operator takes. With infix, this is always clear.
No, not always. J has words which take one argument on the left and, for example, two on the right. Or three. Or a variable number of arguments on the left (granted, they are `tied` with ` word, but still) and nothing on the right... And Ken Iverson says it's very readable! (To him, at least).
To summarize: I'm still not convinced that there is a major and unfixable difference in readability between the notations, and I still think you can make all 3 notations as readable as any other.
((1 2 +) (3 4 +) *)
is fundamentally different from 1 2 3 4 + + *
Each word has a clear arity, and the arguments are delimited. We can follow the evaluation of the parenthesized expression in multiple orders and they come up with the same answer.And in Forth case, you can very easily define your own delimiters:
: [ ;
: ] ;
which should make you able to write: [ [ 1 2 + ] [ 3 4 + ] * ] .
21 ok
(tested with gforth and works [EDIT: but of course breaks Forth! Both [ and ] are already defined, so in practice you'd rather choose another chars])I mean, there is no rule saying that postfix notation cannot provide grouping constructs. I still fail to see a fundamental difference here :)
BTW, it's not going as fast as I'd like, but I managed to parse TXR man page and use it for displaying docs along auto-completion: https://github.com/piotrklibert/txr-mode/blob/master/screen....
I think I'll be able to find some time this weekend (or next weekend) to clean up the code and make it usable for others as well :)