I reported some important distinction between Dictionaries and Sets at 
http://bugs.squeak.org/view.php?id=7258.
The problem has been introduced by the change of Association>>#=.
Logically, Dictionary should have been detached from Set at this time, 
since it was no more a Set of associations as it used to.

Stéphane Ducasse <stephane.duca...@...> writes:

 >
 > This is interesting that you present that as a Bag. I'm too sick now  
 > (my brain
 > is wandering across my room) to really reply something clever.
 >
 > I thought that a bag was more an counting elements container
 >

For me the sole specification is that a Bag unlike a Set can hold 
several equal elements.
The fact that it can count them fast rather than enumerating the whole 
collection is an implementation detail (an important detail of course).

 > > a) multiple values can be in the dictionary:
 > >     (Dictionary new) at: 'one' put: 1; at: 'first' put: 1; yourself.
 >
 > For me to be bag would mean more
 >
 > > dc := (DictionaryBag new) at: 'one' put: 1; at: 'one' put: 2;  
 > > yourself.
 >    dc at: one
 >     -> #(1 2)
 >
 > Stef    
 >

a DictionaryOfBags ?

One thing Dictionary is not : a Bag of associations.
Think of it as a Bag of values.
As long as you don't override a key, a Dictionary behaves like a Bag:

digits := 0 to: 9.
b := Bag new.
d := Dictionary new.
digits do: [:i | b add: i//2].
digits do: [:i | d at: i printString put: i//2].
digits do: [:i |
   self assert:  (b occurrencesOf: i) = (d occurrencesOf: i)].

Personnally, I would expect
    d values.
to answer a Bag (unordered) rather than an Array (arbitrary order)...
The only advantage of an Array is that it is faster than a  Bag...


_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to