If an expression like 2.0 * 4.0 / 3.0 * 5.0
is actually a series of method calls on Doubles
.
Here they are in order from lowest to highest precedence:
1. All letters
2. |
3. ^
5. < >
6. = !
7. :
8. + -
9. * / %
10. All other special characters
When =
is used for assignment, in which case it has the lowest precedence.
In a sequence of left-associative method invocations, they simply bind in left-to-right order. Aren’t all methods “left-associative”? No. In Scala, any method with a name that ends with a colon (:
) binds to the right, while all other methods bind to the left.
For example, you can prepend an element to a List
using the ::
method, called “cons,”which is short for “constructor,”:
scala> 'a' :: List('b', 'c') // Be equivalent to list.::('a')
res2: List[Char] = List(a, b, c)
Ref