Re: rfc: pow-operator

From: Date: Sun, 24 Nov 2013 05:46:23 +0000
Subject: Re: rfc: pow-operator
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-70344@lists.php.net to get a copy of this message
On the left-vs-right-vs-non-associative debate: it seems to me that the reason for supporting associativity for any binary operator is to cut down on the number of parentheses that must be typed, which can help cut down on visual clutter. Otherwise, you might as well use a Lisp. (What are other reasons?) If that's true, then whether to pick left or right association should depend on the most common use-case. Personally, I'd be much more likely to mean 2**(3**2), as (2**3)**2 is equivalent to 2 ** (3*2) but is less performant. Also, by making ** right-associative, 2**3**2 is visually more distinct from 2 ** (3*2); if left-associative, 2 ** (3 ** 2) and 2 ** (3*2) would be more easily confused when reading or writing. Closely related to the power-tower argument is the relation between associativity and hyper operations<https://en.wikipedia.org/wiki/Hyperoperation>, which offers another reason why right association is more natural in mathematics. Defining hyper operations in terms of hypo operations (successor -> addition -> multiplication -> exponentiation -> tetration ...) requires right associativity. However, as addition and multiplication are associative (and the computational versions of these operations aren't usually implemented in terms of each other), it doesn't much matter whether they're made left- or right-associative. For reasons others have stated in this conversation, computational + and * are generally implemented as left-associative. Mathematical exponentiation isn't associative (hence this whole debate), so the reasons for allowing a switch from right- to left- association simply isn't present. Of course, the computational operators aren't the same as the mathematical, so this isn't actually a rigorous argument in favor of right association. Finally, here's a graphic depicting the "exponentiation is right-associative in math" argument (sorry text-readers, you'll have to go to http://i.imgur.com/G9aIn6X.png if you want to see the image): [image: Inline image 2] Of course, this doesn't help at all to determine whether ** should be associative or not.

« previous php.internals (#70344) next »