Re: silly question: prefix vs postfix ops

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Mon, 03 Mar 2008 12:12:28 -0800

          From comp.compilers

Related articles
silly question: prefix vs postfix ops rosing@peakfive.com (MattR) (2008-03-03)
Re: silly question: prefix vs postfix ops csaavedra@alumnos.utalca.cl (Claudio Saavedra) (2008-03-03)
Re: silly question: prefix vs postfix ops mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-03-03)
Re: silly question: prefix vs postfix ops gah@ugcs.caltech.edu (glen herrmannsfeldt) (2008-03-03)
Re: silly question: prefix vs postfix ops haberg_20080207@math.su.se (Hans Aberg) (2008-03-03)
Re: silly question: prefix vs postfix ops marcov@stack.nl (Marco van de Voort) (2008-03-03)
Re: silly question: prefix vs postfix ops gah@ugcs.caltech.edu (glen herrmannsfeldt) (2008-03-04)
Re: silly question: prefix vs postfix ops dot@dotat.at (Tony Finch) (2008-03-04)
Re: silly question: prefix vs postfix ops rpboland@gmail.com (Ralph Boland) (2008-03-04)
Re: silly question: prefix vs postfix ops alexc@TheWorld.com (Alex Colvin) (2008-03-05)
[1 later articles]
| List of all articles for this month |

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Mon, 03 Mar 2008 12:12:28 -0800
Organization: Compilers Central
References: 08-03-012
Keywords: syntax, design
Posted-Date: 03 Mar 2008 16:18:27 EST

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


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.