[Pharo-project] Dictionary as a Set
Dear List, I was wondering whether I am the only one shocked when I see this: (Set new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> true (Set new add: #b -> 'B'; yourself) includes: 'B' ====> false (Dictionary new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> false (Dictionary new add: #b -> 'B'; yourself) includes: 'B' ====> true Dictionary inherits from Set. This means that if Set would have a contract, it would break in Dictionary. IMO, we should have (Dictionary new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> true (Dictionary new add: #b -> 'B'; yourself) includes: 'B' ====> false No? Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
On Mon, Dec 29, 2008 at 12:23 PM, Alexandre Bergel <Alexandre.Bergel@inria.fr> wrote:
I was wondering whether I am the only one shocked when I see this:
(Set new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> true (Set new add: #b -> 'B'; yourself) includes: 'B' ====> false
(Dictionary new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> false (Dictionary new add: #b -> 'B'; yourself) includes: 'B' ====> true
Dictionary inherits from Set. This means that if Set would have a contract, it would break in Dictionary. IMO, we should have (Dictionary new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> true (Dictionary new add: #b -> 'B'; yourself) includes: 'B' ====> false
No?
No :-). I guess #add: has (should have) no meaning for a dictionary and should not be implemented. -- Damien Cassou http://damiencassou.seasidehosting.st
On Dec 29, 2008, at 12:23 PM, Alexandre Bergel wrote:
Dear List,
I was wondering whether I am the only one shocked when I see this:
(Set new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> true (Set new add: #b -> 'B'; yourself) includes: 'B' ====> false
this is correct
(Dictionary new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> false (Dictionary new add: #b -> 'B'; yourself) includes: 'B' ====> true
we should check the semantics of includes:
Dictionary inherits from Set. This means that if Set would have a contract, it would break in Dictionary. IMO, we should have (Dictionary new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> true (Dictionary new add: #b -> 'B'; yourself) includes: 'B' ====> false
No?
Dictionary and Set relationship is subclassing so a lot can be strange. We should fix that in Bloc.
Alexandre
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Stéphane Ducasse <stephane.ducasse@...> writes:
On Dec 29, 2008, at 12:23 PM, Alexandre Bergel wrote:
Dear List,
I was wondering whether I am the only one shocked when I see this:
(Set new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> true (Set new add: #b -> 'B'; yourself) includes: 'B' ====> false
this is correct
(Dictionary new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> false (Dictionary new add: #b -> 'B'; yourself) includes: 'B' ====> true
we should check the semantics of includes:
Dictionary inherits from Set. This means that if Set would have a contract, it would break in Dictionary. IMO, we should have (Dictionary new add: #b -> 'B'; yourself) includes: #b -> 'B' ====> true (Dictionary new add: #b -> 'B'; yourself) includes: 'B' ====> false
No?
Dictionary and Set relationship is subclassing so a lot can be strange. We should fix that in Bloc.
From the st80 origin, Dictionary is a Bag of values. Each value is indexed with a unique key.
It is a Bag because: a) multiple values can be in the dictionary: (Dictionary new) at: 'one' put: 1; at: 'first' put: 1; yourself. b) values are unordered: | d1 d2 | (d1 := Dictionary new: 3) at: 'one' put: 1; at: 'two' put: 2. (d2 := Dictionary new: 4) at: 'one' put: 1; at: 'two' put: 2. stream := (String new: 64) writeStream. d1 do: [:v | stream print: v; cr]. d2 do: [:v | stream print: v; cr]. stream contents. And as you can see, #do: does apply on values, as would #collect: #select: #reject: #includes: etc... The fact that Dictionary is implemented with Associations could be seen as a private implementation defined feature. Though, by tradition, associationsDo: has been made a public interface, so as the possibility to directly add an Association. But semantically, Dictionary is not a Set of Associations. Example: (Set new) add: $a->65; add: $a->1; yourself. (Dictionary new) add: $a->65; add: $a->1; yourself. Dictionary could be viewed as a Set of keys.
From that POV, it shared enough property with Set to be implemented as a subclass. That's all. I proposed once to detach Set and Dictionary from a common ancestor just for clarity...
Nicolas
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
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
From the st80 origin, Dictionary is a Bag of values. Each value is indexed with a unique key.
It is a Bag because: a) multiple values can be in the dictionary: (Dictionary new) at: 'one' put: 1; at: 'first' put: 1; yourself. b) values are unordered: | d1 d2 | (d1 := Dictionary new: 3) at: 'one' put: 1; at: 'two' put: 2. (d2 := Dictionary new: 4) at: 'one' put: 1; at: 'two' put: 2. stream := (String new: 64) writeStream. d1 do: [:v | stream print: v; cr]. d2 do: [:v | stream print: v; cr]. stream contents. And as you can see, #do: does apply on values, as would #collect: #select: #reject: #includes: etc...
The fact that Dictionary is implemented with Associations could be seen as a private implementation defined feature. Though, by tradition, associationsDo: has been made a public interface, so as the possibility to directly add an Association.
But semantically, Dictionary is not a Set of Associations. Example: (Set new) add: $a->65; add: $a->1; yourself. (Dictionary new) add: $a->65; add: $a->1; yourself.
Dictionary could be viewed as a Set of keys.
From that POV, it shared enough property with Set to be implemented as a subclass. That's all. I proposed once to detach Set and Dictionary from a common ancestor just for clarity...
Nicolas
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
participants (4)
-
Alexandre Bergel -
Damien Cassou -
nicolas cellier -
Stéphane Ducasse