- About Scala
- In the Enterprise
- Scala Community
- Language Research
- In the Press
- The Scala Team
- Scala's Prehistory
- Contact Us
- Learning Scala
- Tour of Scala
- Scala API
- Setup & Getting Started
- Programming Guides
- Other Guides
- Code Examples
- Scala Developers
Fwd: exponential operator
Thu, 2011-12-22, 23:00
On Thu, Dec 22, 2011 at 3:55 PM, Erik Osheim <erik [at] plastic-idolatry [dot] com> wrote:
1. Hardcode some fixed operators amidst the general precedence rules,
allowing things like ** to be higher priority than *, and to have the
correct associativity. This is weird, but no weirder than the hardcoded
precedence table, or the hardcoded list of unary prefix ops.
Ick. This is no weirder, but it adds to the memorization burden. Just use \* and ~* instead of **!
2. Generalize the current rules to use all non-letter/number
characters. For instance, ++ would be higher priority than + (which are
currently the same), and ** would be higher priority than * (which are
also currently the same). It's likely this would introduce problems in
practice but given that operators at the same precedence level
currently need to be grouped in some cases I expect this change would
simply change which situations required this.
Double-ick. a & b && c -- types don't match, but if they did, would you really expect a & (b && c)? I would expect the opposite. How about a ++ b + c with collections (with adding an element); do you really expect the collection-operation to be first?
** does not at all look to me like exponentiation anyway. I understand that it does for people with certain backgrounds, but there are plenty of other repeated operator symbols that do not obviously increase precedence.
Also: suppose u and v are vectors. What would u ** v be? Probably not exponentiation; if it meant anything, it'd be, akin to collections, either a dot product or matrix multiplication or somesuch.
I think one of x pow y, x ~^ y, x \^ y is the way to go.