From: Dave Thomas Date: 2001-07-13T22:57:39+09:00 Subject: [ruby-talk:17794] Re: What is Array#- ? matz@ruby-lang.org (Yukihiro Matsumoto) writes: > There's no reason to make "-" to remove duplication (other than > performance), so that if someone persuade me, it might be change in > the future. In that case, it would be useful to define new > operation for set subtraction, maybe. Matz: Wouldn't it be clearer to define a new Set type, rather than new operations? My thinking is this: Arrays are ordered collections of things. There's no contract about uniqueness: you simply put an object into an array at a certain position and it sits there. There is nothing inherently Set-like about an array. However, sometimes it's convenient to have Sets, collections where there's only ever one of each element. These have different semantics to arrays: they are not necessarily ordered, attempting to add an element doesn't necessarily increase the size, and so on. Right now, we have a couple of set-like operations in the Array methods. But these don't make Arrays into Sets, as the set-like behavior is only temporary: the object is normalized into a set as a result of the operation, but at the next insert it can turn back into a bag. Adding more set-like operations won't really help: if people want this kind of behavior they can have it already just by tacking 'uniq' on to whatever operations they're using. So my vote would be to create a new Set class (possibly delegating to Hash, but that's an implementation detail), and to add the new set methods to it. I'd then vote to remove the magical properties from Array#-, and I'd suggest changing Array#| to operate more like 'or': elements in common between the operands aren't duplicated: [ 1, 1, 2, 4, 4, 4 ] | [ 1, 2, 2, 3 ] => [ 1, 1, 2, 2, 3, 4, 4, 4 ] If we did this, it might be an idea to start a DataStructures or Collections extension where all there various Sets, Bags, BW Trees and so on might live. Regards Dave