From: Surendra Singhi Date: 2006-09-13T03:28:21+09:00 Subject: Re: Matrix Hi, Paul Lutus writes: > MonkeeSage wrote: > > / ... > >> Anyhow, I don't really care if []= is there by default, I can add it if >> I want it; but I just don't understand why "a matrix [as a value] is >> immutable" means that []= shouldn't be there regarding the data >> structure. > > You might as well ask why there is no formal method to change the third > digit of an integer in class Fixnum. irb(main):001:0> x="hello" => "hello" irb(main):002:0> x[0] = 'w' => "w" irb(main):003:0> x => "wello" Why is the above allowed? By the same argument, shouldn't strings be immutable. > > Most matrix operations operate on matrices as units. Here's an example, a > matrix from my library, responsible for rotating objects in three-space: I don't agree, the only example which I have heard is people talking about matrix rotation, what about scaling matrices, there are several other matrix operations. > def convert_3d_to_2d(x,y,z,anaglyph_flag) > x = (x * (PerspectiveDepth + z))/PerspectiveDepth > x += z * anaglyph_flag * AnaglyphScale if anaglyph_flag > y = (y * (PerspectiveDepth + z))/PerspectiveDepth Ruby should allow these operations in place, what if you want to scale just one row? Is there any guarantee, the implementation of matrix won't change, and "@rows" will be there forever? Cheers, -- Surendra Singhi http://ssinghi.kreeti.com, http://www.kreeti.com Read my blog at: http://cuttingtheredtape.blogspot.com/ ,---- | Great wits are sure to madness near allied, | And thin partitions do their bounds divide. | | (John Dryden, Absalom and Achitophel, 1681) `----