"Michael Ulm" <michael.ulm / isis-papyrus.com> wrote in message news:45068941.6020009 / isis-papyrus.com... > Dave Burt wrote: > >> Michael Ulm wrote: >> >>>I think he's trying to say, that there is no rational reason for >>>leaving out the []= operator, and I agree. >> >> The benefit is that you can assume no other code is modifying your >> matrix. >> >> n = Matrix.I(2) >> some_function(n) >> p n # same as before >> >> It's a good feature. > > You are right, this is a somewhat useful feature (I've been bitten often > enough by mutated Arrays). However, this only works as long as > some_function > is not a third party application (or calls a third party library). Why do you think this? A method doesn't have to be third party to modify the passed in object... >> []= would be useful, too, but I think to keep the immutability a better >> addition that provides the same functionality could be provided; a >> modified_at(x,y,value) method or something, but naming it is hard. > > Then the whole Matrix would have to be copied to change one value -- > goodbye performance. This is (apparently) true for all "number" types, including complex numbers and matrices. Performance is not a priority. I suspect that performance was never a priority in Ruby, either. The fact it is trivial to add your own in-place modifier probably contributed to its obsence...