Re: Re: internals Digest 23 Nov 2013 00:01:03 -0000 Issue 3138
| From: | Sherif Ramadan | Date: | Sat, 23 Nov 2013 02:02:44 +0000 |
| Subject: | Re: Re: internals Digest 23 Nov 2013 00:01:03 -0000 Issue 3138 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70309@lists.php.net to get a copy of this message | ||
On Fri, Nov 22, 2013 at 8:47 PM, Walter Parker <walterp@gmail.com> wrote:
> The Wikipedia page on Operator associativity, at
> http://en.wikipedia.org/wiki/Operator_associativity, says the
> following:
>
> Associativity is only needed when the operators in an expression have
> the same precedence. Usually + and - have the same precedence.
> Consider the expression 7 - 4 + 2. The result could be either (7 - 4)
> + 2 = 5 or 7 - (4 + 2) = 1. The former result corresponds to the case
> when + and - are left-associative, the latter to when + and - are
> right-associative.
>
> In order to reflect normal mathematical usage, addition, subtraction,
> multiplication, and division operators are usually left-associative
> while an exponentiation operator (if present) is right-associative.
> Any assignment operators are also typically right-associative. To
> prevent cases where operands would be associated with two operators,
> or no operator at all, operators with the same precedence must have
> the same associativity.
>
>
> Walter
>
>
> ---------- Forwarded message ----------
> >
> > From: Sherif Ramadan <theanomaly.is@gmail.com>
> > To: Jakub Zelenka <bukka@php.net>
> > Cc: Nikita Popov <nikita.ppv@gmail.com>, Tjerk Meesters <
> tjerk.meesters@gmail.com>, PHP Internals <internals@lists.php.net>
> > Date: Fri, 22 Nov 2013 19:00:59 -0500
> > Subject: Re: [PHP-DEV] Power function as operator
> > On Fri, Nov 22, 2013 at 6:59 PM, Jakub Zelenka <bukka@php.net> wrote:
> >
> > > Hi,
> > >
> > >
> > >> I'm not entirely sure that making it non-associative is a great idea
> > >> either, but I have to agree that it does find *some* middle ground.
> > >> Right-associative exponent operator didn't seem right to me either.
> > >>
> > >
> > > I think there is a good mathematical reason for right associative
> > > exponent. It calls tetration or power tower. Please look at following
> > > sources for more details:
> > >
> > >
> > > http://math.stanford.edu/circle/notes08f/bignumbers.pdf
> > > http://en.wikipedia.org/wiki/Tetration
> > > http://mathworld.wolfram.com/PowerTower.html
> > >
> > > Regards
> > >
> > > Jakub
> > >
> >
> >
> > Right, that would be why I'm not *entirely* convinced.
> >
>
>
>
> --
> The greatest dangers to liberty lurk in insidious encroachment by men
> of zeal, well-meaning but without understanding. -- Justice Louis D.
> Brandeis
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I think that's about the worst possible example for operator associativity
there is. Trying to distinguish order of operations in operators of the
same precedence is a moot point since math tells us they should be carried
out in the order they presented in. 7 - 4 + 2 should always be ((7 - 4) +
2) in any sane implementation of an operator precedence parser.
As for exponentiation being right-associative, I also disagree with that
article. The exponent operator doesn't have to be right associative. It
just has to have a higher precedence than multiplication. I would suggest
correcting the false claims made in that wikipedia article before quoting.