I am still sometimes puzzled by scala occasional syntactic magic.
I thought, that writing
array(5)
is just a shortcut for
array.apply(5). (As is written in the documentation for Array.)
However, I can do quite happily
array(5) = 3
But I cannot do
array.apply(5) = 3.
What is going on?
There are different rules on the left side of
=:a.x = bis translated toa.x_=(b)(provided there is also an x() method)a(i1,... in) = bis transformed intoa.update(i1...,in, b)So
array(5) = 3isarray.update(5,3)Of course, for arrays it is directly compiled to an array write without a method call in between.