> -----Original Message----- > From: gotoken / hanare00.math.sci.hokudai.ac.jp > [mailto:gotoken / hanare00.math.sci.hokudai.ac.jp]On Behalf Of GOTO > Kentaro > Sent: Sunday, January 07, 2001 03:55 PM > To: ruby-talk ML > Subject: [ruby-talk:8800] Re: No :<, :>, etc. methods for Array > I think such collections can be implemented as extension libraries if > one needs efficiency. Maybe designing interfaces is too difucult for > built-in specialized collections because we are greedy, and must want > many special methods for each of them, but our taste are more > different in case of special cases than in the general case. I have > such experience in the development working of NumArray (in RAA). I see your point ... . I guess my idea was to be less greedy and to reorganize the current Array and Hash classes in a class hierarchy which effectively takes away (and sometimes adding and/or redefining) most of their current functionality. The core languages does not provide among others things a predefined Stack class, (Multi)Set (or their ordered variants)- instead this functionality was ``crammed into'' the Hash and Array container classes taking away clarity of intent, functionality, possible optimizations and as Kevin points out creating class interfaces with a pretty steep learning curve. In my opinion it would be a good thing if the standard Ruby distribution would ship with a ``nice library'' of well integrated basic container classes > >> def sum(if_empty = 0) # Is the integer zero suitable? > >An alternative would be the introduction of a ZERO and ONE constants > >in the Numeric class (possibly overridden in subclasses)? > > Because sum is defined in the context of container class, such > constants have to be given with their scope. From would you are saying it seems that the container class should effectively provide this generic zero. What about something like class ContainerClass ZERO = 0 # or something similar like the hypothetical Numeric::ZERO def def sum(if_empty = type::ZERO) .. end ... end This way you can override the generic ZERO in a specialized ContainerClass > However, ONE and especially ZERO sound interesting. They will reduce > magics in code, perhaps. Thanks Christoph