JoeStrout / miniscript

source code of both C# and C++ implementations of the MiniScript scripting language
MIT License
275 stars 64 forks source link

Consider changing associativity of ^ #172

Open JoeStrout opened 1 month ago

JoeStrout commented 1 month ago

The ^ operator in MiniScript is left-associative. There is no universal standard for this, but right associativity for this is somewhat more common, and the current behavior has surprised at least one user.

Other languages are not very consistent about this: https://codeplea.com/exponentiation-associativity-options

Of the languages surveyed here, 11 are right-associative, and 6 are left-associative. Even handheld calculators don't all agree on this.

https://en.wikipedia.org/wiki/Exponentiation#In_programming_languages says that "most" languages make it right-associative, but notable exceptions are Algol, MATLAB, and Excel, which could all be considered "math-oriented" languages.

So, hmm.

Given all this, I'm inclined to say that it would be better if it were right-associative. The question is, should we risk breaking code by changing the design at this point? I'm not sure.