MattR wrote:
> This is more of a language question than a compiler question (and
> therefore should create a religious battle :) ), but I'm wondering if
> the answer has more to do with the compiler. Anyway, why are there
> prefix operators that could just as well be postfix?
I believe it is the combination of mathematical notation
and the convenience of the user. Mathematics likes prefix
(unary + and -, the f(x), d/dx and integration) operators,
and infix (binary +, -, *, /, **) operators. Prefix unary
and infix operators were used in Fortran and, more or less,
inherited by other languages. I found out recently that
Fortran was the first computer language to allow multiple
character variable names.
> Why is it !a and
> not a!, or *a and not a* ? I can understand the increment and
> decrement operators, and the & op but expressions like *a[i] would be
> a lot clearer if it were a[i]*, just read the operators from right to
> left. Is it a case of, well, it's always been done this way?
Postfix notation is convenient for stack oriented calculators,
where the operator key indicates not only the operation but when to
apply the operation. As I understand it, HP called it RPN, as
it was based on a prefix notation used by a certain Polish
mathematician, converted to postfix.
In the 1970's there were arguments between HP promoting its PRN
calculators and TI with its algebraic calculators. TI claiming to
match the way people write math, HP to the way people think about it.
In addition, note that in Fortran subscripting and function call
are not operators, as they are in C. (One can't subscript a function
that returns an array in Fortran, for example.) So, Fortran and
many other languages don't have any postfix operators. The function
call syntax (not operator) is similar to the mathematical function
call notation.
It seems to me that postfix is useful for hand calculators,
but not for compiled languages where the whole expression is
available at compile time.
-- glen


|
27 Posts in Topic:
|
MattR <rosing@[EMAIL P |
2008-03-03 10:37:52 |
|
Claudio Saavedra <csaa |
2008-03-03 16:24:45 |
|
"Dmitry A. Kazakov&q |
2008-03-03 20:42:38 |
|
Alex Colvin <alexc@[EM |
2008-03-05 22:02:05 |
|
Hans-Peter Diettrich < |
2008-03-06 14:28:53 |
|
glen herrmannsfeldt <g |
2008-03-03 12:12:28 |
|
Hans Aberg <haberg_200 |
2008-03-03 22:10:19 |
|
Marco van de Voort <ma |
2008-03-03 22:23:48 |
|
glen herrmannsfeldt <g |
2008-03-04 03:06:11 |
|
wclodius@[EMAIL PROTECTED |
2008-03-04 20:25:54 |
|
wclodius@[EMAIL PROTECTED |
2008-03-05 20:06:38 |
|
anw@[EMAIL PROTECTED]
(A |
2008-03-07 01:18:09 |
|
torbenm@[EMAIL PROTECTED] |
2008-03-07 09:32:16 |
|
Hans-Peter Diettrich < |
2008-03-09 20:16:38 |
|
glen herrmannsfeldt <g |
2008-03-10 14:39:21 |
|
Hans-Peter Diettrich < |
2008-03-14 04:27:31 |
|
"Dmitry A. Kazakov&q |
2008-03-14 18:53:32 |
|
"Aleksey Demakov&quo |
2008-03-14 12:26:59 |
|
torbenm@[EMAIL PROTECTED] |
2008-03-14 09:41:57 |
|
"Derek M. Jones" |
2008-03-15 11:51:55 |
|
Alex Colvin <alexc@[EM |
2008-03-14 22:22:20 |
|
Carl Barron <cbarron41 |
2008-03-10 19:37:16 |
|
glen herrmannsfeldt <g |
2008-03-14 00:16:14 |
|
wclodius@[EMAIL PROTECTED |
2008-03-10 19:50:56 |
|
Louis Krupp <lkrupp@[E |
2008-03-15 17:38:17 |
|
Tony Finch <dot@[EMAIL |
2008-03-04 14:20:02 |
|
Ralph Boland <rpboland |
2008-03-04 17:59:29 |
|