digitalmars.D - Should ^^ (opPow) be left- or right-associative?
- KennyTM~ (11/11) Dec 05 2009 Currently in D (r283) opPow is left-associative:
- bearophile (5/8) Dec 05 2009 Doing things as in mathematical convention, Mathematica and Python sound...
- dsimcha (4/5) Dec 05 2009 improvements :-)
- Don (5/15) Dec 05 2009 Fortran too.
- Nick Sabalausky (7/24) Dec 05 2009 Quick summary for those who don't want to dig through that whole page:
- Tim Matthews (11/30) Dec 05 2009 Don I thought you were the one who created the patch
- Don (4/29) Dec 05 2009 It was a quick patch to determine if Walter could be swayed to include
- Tim Matthews (4/8) Dec 05 2009 Ok thanks a lot for getting a truly important operator implemented. I
Currently in D (r283) opPow is left-associative: import std.stdio; void main() { // prints 19683 instead of 7625597484987: writeln(3.0 ^^ 3.0 ^^ 3.0); } But the mathematical convention is a^b^c == a^(b^c). Languages which the power operator is right-associative (3^3^3==7e12): - Python, Haskell, Ruby, Perl, Mathematica, Bash. Languages which the power operator is left-associative (3^3^3==19683): - Octave/MATLAB, Excel, BASIC.
Dec 05 2009
KennyTM~:But the mathematical convention is a^b^c == a^(b^c). Languages which the power operator is right-associative (3^3^3==7e12): - Python, Haskell, Ruby, Perl, Mathematica, Bash.Doing things as in mathematical convention, Mathematica and Python sounds better. This was just the release V.0.1 of the built-in pow, it needs several improvements :-) Bye, bearophile
Dec 05 2009
== Quote from bearophile (bearophileHUGS lycos.com)'s articleThis was just the release V.0.1 of the built-in pow, it needs severalimprovements :-) See also bug 3577. ^^ should have higher precedence than * and / to be consistent w/ mathematical convention. http://d.puremagic.com/issues/show_bug.cgi?id=3577
Dec 05 2009
bearophile wrote:KennyTM~:Fortran too. Here's a link from the TCL language, with a nice explanation of the rationale for choosing right associativity. http://www.tcl.tk/cgi-bin/tct/tip/274.htmlBut the mathematical convention is a^b^c == a^(b^c). Languages which the power operator is right-associative (3^3^3==7e12): - Python, Haskell, Ruby, Perl, Mathematica, Bash.Doing things as in mathematical convention, Mathematica and Python sounds better. This was just the release V.0.1 of the built-in pow, it needs several improvements :-) Bye, bearophile
Dec 05 2009
"Don" <nospam nospam.com> wrote in message news:hfei3u$kvk$1 digitalmars.com...bearophile wrote:Quick summary for those who don't want to dig through that whole page: (a ^^ b) ^^ c == a ^^ (b * c) <-- For all real values of a, b, and c So kinda useless, but... a ^^ (b ^^ c) == .... a ^^ (b ^^ c) So more useful.KennyTM~:Fortran too. Here's a link from the TCL language, with a nice explanation of the rationale for choosing right associativity. http://www.tcl.tk/cgi-bin/tct/tip/274.htmlBut the mathematical convention is a^b^c == a^(b^c). Languages which the power operator is right-associative (3^3^3==7e12): - Python, Haskell, Ruby, Perl, Mathematica, Bash.Doing things as in mathematical convention, Mathematica and Python sounds better. This was just the release V.0.1 of the built-in pow, it needs several improvements :-) Bye, bearophile
Dec 05 2009
Don wrote:bearophile wrote:Don I thought you were the one who created the patch http://d.puremagic.com/issues/show_bug.cgi?id=3481 What was your reason for the choice of left associativity? To cite wikipedia: http://en.wikipedia.org/wiki/Associativity#Notation_for_non-associative_operations "x^{y^z}=x^{(y^z)}.\, The reason exponentiation is right-associative is that a repeated left-associative exponentiation operation would be less useful. Multiple appearances could (and would) be rewritten with multiplication: (x^y)^z=x^{(yz)}.\,"KennyTM~:Fortran too. Here's a link from the TCL language, with a nice explanation of the rationale for choosing right associativity. http://www.tcl.tk/cgi-bin/tct/tip/274.htmlBut the mathematical convention is a^b^c == a^(b^c). Languages which the power operator is right-associative (3^3^3==7e12): - Python, Haskell, Ruby, Perl, Mathematica, Bash.Doing things as in mathematical convention, Mathematica and Python sounds better. This was just the release V.0.1 of the built-in pow, it needs several improvements :-) Bye, bearophile
Dec 05 2009
Tim Matthews wrote:Don wrote:It was a quick patch to determine if Walter could be swayed to include it, if he didn't need to implement it. I didn't get any positive feedback about it until it was put into svn.bearophile wrote:Don I thought you were the one who created the patch http://d.puremagic.com/issues/show_bug.cgi?id=3481 What was your reason for the choice of left associativity?KennyTM~:Fortran too. Here's a link from the TCL language, with a nice explanation of the rationale for choosing right associativity. http://www.tcl.tk/cgi-bin/tct/tip/274.htmlBut the mathematical convention is a^b^c == a^(b^c). Languages which the power operator is right-associative (3^3^3==7e12): - Python, Haskell, Ruby, Perl, Mathematica, Bash.Doing things as in mathematical convention, Mathematica and Python sounds better. This was just the release V.0.1 of the built-in pow, it needs several improvements :-) Bye, bearophile
Dec 05 2009
Don wrote:It was a quick patch to determine if Walter could be swayed to include it, if he didn't need to implement it. I didn't get any positive feedback about it until it was put into svn.Ok thanks a lot for getting a truly important operator implemented. I tried to give my feedback in the ng post back in august http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=95596
Dec 05 2009