From: William Djaja Tjokroaminata Date: 2002-01-26T07:32:19+09:00 Subject: Re: Serious Array Bug in Ruby 1.6.6? Christoph, Thank you, thank you for summarizing it quite well. For me with C/C++ background, it is much easier to just say all Ruby references or variables are pointers (except the FixNum, True, etc.) So basically Ruby only supports ... pointer = &(new (object)); vector a = new (n, pointer); and not vector a = new (n, object); (excuse me if the syntax is wrong; I have not used C++ for a long time). Yes, the List class is exactly what I want. I don't see why it is so inefficient, because the opposite is I still don't see the use of an array of pointers to the same object. If it is so inefficient, why just don't provide it to the user: Array.new (n, obj) only works for obj of FixNum, True, Nil, etc. On the other hand, if it is allowed for obj to be a Hash, then why not create multiple hashes instead of just a single hash. Ruby has done a lot of checkings, like public/protected/private methods, and attr_reader/attr_accessor methods. For Array, why not just check the type/class of obj when the array is created, just like what you do for singleton? If a program has to create and destroy arrays many many times, probably it should have been written in C. Regards, Bill =========================================================================== Chr. Rippel wrote: > Actually Rubys Arrays are an abstraction of an C/C++ array of pointers. > What you really want is a List class free of side-effects > ---- > class Object > def _dup > begin > dup > rescue TypeError > self # for classes implementing the Singleton pattern > end > end > end > class List < Array > def initialize (nums, ini = nil) > super(nums).collect! do |e| e._dup end > end > def []=(l,r) > super (l,r._dup) > end > def [](l) > super(l)._dup > end > end > ---- > Yes lists are great but they are also terribly inefficient and even > functional languages need to introduce Ruby-type Arrays through > the back door. > /Christoph