[Pharo-project] SmallDictionary>>removeAll or >>empty?
Stupid question: how do I remove all entities from a SmallDictionary Let's take: d := SmallDictionary new. d add: $d -> 4. d add: $e -> 5. d If I do d empty then d size = 0 and d do: behaves as if there is nothing BUT someone can still perform d at: $d -> 5 If I do d removeAll I get a MessageNotUnderstood: SmallInteger>>key because #removeAll inherited from Collection expects a different structure -- Simon
SmallDictionary comes from the refactoring engine. It is a highly optimized dictionary originally intended for parse-tree matching. The method #empty does not make sense outside that context. The method #removeAll is implemented in Collection. I don't think that this implementation can ever work in any concrete collection implementation, because it modifies the collection while iterating over it (lint would know that). Most classes override it with something sensible though. Lukas 2009/12/5 Simon Denier <Simon.Denier@inria.fr>:
Stupid question: how do I remove all entities from a SmallDictionary
Let's take: d := SmallDictionary new. d add: $d -> 4. d add: $e -> 5. d
If I do d empty
then d size = 0 and d do: behaves as if there is nothing BUT someone can still perform d at: $d -> 5
If I do d removeAll
I get a MessageNotUnderstood: SmallInteger>>key because #removeAll inherited from Collection expects a different structure
-- Â Simon
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Lukas Renggli http://www.lukas-renggli.ch
this is strange since I recall nicolas or somebody proposing a real removalAll. So I would have thought it would work. Stef On Dec 5, 2009, at 5:49 PM, Lukas Renggli wrote:
SmallDictionary comes from the refactoring engine. It is a highly optimized dictionary originally intended for parse-tree matching. The method #empty does not make sense outside that context.
The method #removeAll is implemented in Collection. I don't think that this implementation can ever work in any concrete collection implementation, because it modifies the collection while iterating over it (lint would know that). Most classes override it with something sensible though.
Lukas
2009/12/5 Simon Denier <Simon.Denier@inria.fr>:
Stupid question: how do I remove all entities from a SmallDictionary
Let's take: d := SmallDictionary new. d add: $d -> 4. d add: $e -> 5. d
If I do d empty
then d size = 0 and d do: behaves as if there is nothing BUT someone can still perform d at: $d -> 5
If I do d removeAll
I get a MessageNotUnderstood: SmallInteger>>key because #removeAll inherited from Collection expects a different structure
-- Simon
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Lukas Renggli http://www.lukas-renggli.ch
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Lukas is speaking of default Collection>>removeAll which has few chances to work. But subclasses do a better job, that's why I did not bother... Cheers Nicolas 2009/12/5 Stéphane Ducasse <stephane.ducasse@inria.fr>:
this is strange since I recall nicolas or somebody proposing a real removalAll. So I would have thought it would work.
Stef
On Dec 5, 2009, at 5:49 PM, Lukas Renggli wrote:
SmallDictionary comes from the refactoring engine. It is a highly optimized dictionary originally intended for parse-tree matching. The method #empty does not make sense outside that context.
The method #removeAll is implemented in Collection. I don't think that this implementation can ever work in any concrete collection implementation, because it modifies the collection while iterating over it (lint would know that). Most classes override it with something sensible though.
Lukas
2009/12/5 Simon Denier <Simon.Denier@inria.fr>:
Stupid question: how do I remove all entities from a SmallDictionary
Let's take: d := SmallDictionary new. d add: $d -> 4. d add: $e -> 5. d
If I do d empty
then d size = 0 and d do: behaves as if there is nothing BUT someone can still perform d at: $d -> 5
If I do d removeAll
I get a MessageNotUnderstood: SmallInteger>>key because #removeAll inherited from Collection expects a different structure
-- Â Simon
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Lukas Renggli http://www.lukas-renggli.ch
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
On 5 déc. 2009, at 17:49, Lukas Renggli wrote:
SmallDictionary comes from the refactoring engine. It is a highly optimized dictionary originally intended for parse-tree matching. The method #empty does not make sense outside that context.
The method #removeAll is implemented in Collection. I don't think that this implementation can ever work in any concrete collection implementation, because it modifies the collection while iterating over it (lint would know that). Most classes override it with something sensible though.
Back from my trip, my neurons are still not 100% functional. What would be a sensible implementation then? Most straightforward I can think of: SmallDictionary>>removeAll self initliaze
Lukas
2009/12/5 Simon Denier <Simon.Denier@inria.fr>:
Stupid question: how do I remove all entities from a SmallDictionary
Let's take: d := SmallDictionary new. d add: $d -> 4. d add: $e -> 5. d
If I do d empty
then d size = 0 and d do: behaves as if there is nothing BUT someone can still perform d at: $d -> 5
If I do d removeAll
I get a MessageNotUnderstood: SmallInteger>>key because #removeAll inherited from Collection expects a different structure
-- Simon
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Lukas Renggli http://www.lukas-renggli.ch
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Simon
2009/12/7 Simon Denier <Simon.Denier@inria.fr>:
On 5 déc. 2009, at 17:49, Lukas Renggli wrote:
SmallDictionary comes from the refactoring engine. It is a highly optimized dictionary originally intended for parse-tree matching. The method #empty does not make sense outside that context.
The method #removeAll is implemented in Collection. I don't think that this implementation can ever work in any concrete collection implementation, because it modifies the collection while iterating over it (lint would know that). Most classes override it with something sensible though.
Back from my trip, my neurons are still not 100% functional.
What would be a sensible implementation then?
Most straightforward I can think of:
SmallDictionary>>removeAll  self initliaze
or size := 0. keys atAllPut: nil. values atAllPut: nil.
Lukas
2009/12/5 Simon Denier <Simon.Denier@inria.fr>:
Stupid question: how do I remove all entities from a SmallDictionary
Let's take: d := SmallDictionary new. d add: $d -> 4. d add: $e -> 5. d
If I do d empty
then d size = 0 and d do: behaves as if there is nothing BUT someone can still perform d at: $d -> 5
If I do d removeAll
I get a MessageNotUnderstood: SmallInteger>>key because #removeAll inherited from Collection expects a different structure
-- Â Simon
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Lukas Renggli http://www.lukas-renggli.ch
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Â Simon
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
publish the solution to smallDictionary like that we integrate it. On Dec 7, 2009, at 4:47 PM, Simon Denier wrote:
On 5 déc. 2009, at 17:49, Lukas Renggli wrote:
SmallDictionary comes from the refactoring engine. It is a highly optimized dictionary originally intended for parse-tree matching. The method #empty does not make sense outside that context.
The method #removeAll is implemented in Collection. I don't think that this implementation can ever work in any concrete collection implementation, because it modifies the collection while iterating over it (lint would know that). Most classes override it with something sensible though.
Back from my trip, my neurons are still not 100% functional.
What would be a sensible implementation then?
Most straightforward I can think of:
SmallDictionary>>removeAll self initliaze
Lukas
2009/12/5 Simon Denier <Simon.Denier@inria.fr>:
Stupid question: how do I remove all entities from a SmallDictionary
Let's take: d := SmallDictionary new. d add: $d -> 4. d add: $e -> 5. d
If I do d empty
then d size = 0 and d do: behaves as if there is nothing BUT someone can still perform d at: $d -> 5
If I do d removeAll
I get a MessageNotUnderstood: SmallInteger>>key because #removeAll inherited from Collection expects a different structure
-- Simon
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Lukas Renggli http://www.lukas-renggli.ch
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Simon
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
participants (4)
-
Lukas Renggli -
Nicolas Cellier -
Simon Denier -
Stéphane Ducasse