In article <008201c16c79$7dce4fc0$0300a8c0 / austin.rr.com>, Hal E. Fulton wrote:

(...)

>> Is a "bag" the same as C++'s "multiset"?
> 
> I don't know. Never had a use for either.

C++ "multiset" is not exactly the same as Smalltalk's "Bag", 
but close.

A "bag" is a container that happens to remember, how many times 
an object was stored into it. It will stores an object only once
together with a counter and is often realized with a Dictionary 
(Hash in Ruby). A "multiset", however, will really store an 
object n times.

A "Bag" has no order of its elements, a "multiset" defines an 
order based on precedence of its contained elements (one element
precede another) 

Ony example to use it (my first one in Smalltalk, once upon a
time) could be, to count which and how many characters are
contained in a given string.

You could do this as:

  aStr = ...
  howManyDifferent = aStr.to_set.size
  howManyEachOne = aStr.to_bag
  howManyEachOne.each { |c, n| puts "#{c} occured #{n} times" }


HTH,
\cle