|silly question: prefix vs postfix ops firstname.lastname@example.org (MattR) (2008-03-03)|
|Re: silly question: prefix vs postfix ops email@example.com (Claudio Saavedra) (2008-03-03)|
|Re: silly question: prefix vs postfix ops firstname.lastname@example.org (Dmitry A. Kazakov) (2008-03-03)|
|Re: silly question: prefix vs postfix ops email@example.com (glen herrmannsfeldt) (2008-03-03)|
|Re: silly question: prefix vs postfix ops firstname.lastname@example.org (Hans Aberg) (2008-03-03)|
|Re: silly question: prefix vs postfix ops email@example.com (Marco van de Voort) (2008-03-03)|
|Re: silly question: prefix vs postfix ops firstname.lastname@example.org (glen herrmannsfeldt) (2008-03-04)|
|Re: silly question: prefix vs postfix ops email@example.com (Tony Finch) (2008-03-04)|
|Re: silly question: prefix vs postfix ops firstname.lastname@example.org (Ralph Boland) (2008-03-04)|
|Re: silly question: prefix vs postfix ops alexc@TheWorld.com (Alex Colvin) (2008-03-05)|
|[1 later articles]|
|From:||glen herrmannsfeldt <email@example.com>|
|Date:||Mon, 03 Mar 2008 12:12:28 -0800|
|Posted-Date:||03 Mar 2008 16:18:27 EST|
> 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
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.
Return to the
Search the comp.compilers archives again.