3 ms·
I don't think it's really that different -- either Scala does some magic to desugar the operators into method calls taking into account operator preference, or
by seertaak 13y ago
I don't think it's really that different -- either Scala does some magic to desugar the operators into method calls taking into account operator preference, or you're going to get results that don't match expectations. If latter, then like Rebol operators don't match (mathematical) expectation. If former, then there is actually a distinction between methods and operators in Scala, so Scala is just like Python.
Or am I missing something?
- lmm 13y agoIt means that "overloading" an operator in Scala is not a special case - downthread someone was saying this addition to python was great not because they were going to use @ to multiply matrices but because now they could overload @ to do things with their own types. In Scala you wouldn't have to wait for a new operator to be added to the language - "defining a custom operator" is exactly the same as "overloading an existing operator". If you want to make "a + b" work, you define a "+" method on a. If you want to make "a @ b" work, you define an "@" method on a. If you want to make "a ə b" do something, you define a "ə" method. You're right that scala does special-case the precedence of a small number of operators (the list is much shorter than the likes of C, but I still wish we could move away from it).
- draegtun 13y agore: operator precedence Io uses Operator Shuffling to move those operator method calls back into normal mathematical expectation (or to be exact... C precedence order) prior to building the AST. Ruby's parser must do (or does) something similar. From lmm answer it sounds like Scala does something similar to Ruby here. Smalltalk, Self & Rebol have no operator precedence and simply interpret the operators from left to right (using parenthesis to enforce higher precedence). Some refs: - http://iolanguage.org/scm/io/docs/IoGuide.html#Syntax-Operators http://iolanguage.org/scm/io/docs/IoGuide.html#Syntax-Operat... - http://stackoverflow.com/a/2926639/12195 http://stackoverflow.com/a/2926639/12195 - http://www.rebol.com/docs/core23/rebolcore-11.html http://www.rebol.com/docs/core23/rebolcore-11.html