Recap: How to empty a collection

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: ordinary #hash and Dictionary [was: Recap: How to empty a collection]

Klaus D. Witzel
On Wed, 20 Feb 2008 22:12:57 +0100, nicolas cellier wrote:

> Klaus D. Witzel a écrit :
>> On Wed, 20 Feb 2008 00:59:57 +0100, nicolas cellier wrote:
>>  ...
>>> I see, become: does exchange #identityHash, and that makes our  
>>> IdentityDictionary work, god thanks, but there is no such provision  
>>> for ordinary #hash and Dictionary...
>>  But there are sufficient provisions in place, since Smalltalk-80, and  
>> most Dictionary users know about them :)
>>
>>> However, there are plenty of ordinary things that would have the same  
>>> result:
>>>
>>> | key1 key2 dic |
>>> key1 := 'abc' copy.
>>> key2 := 'abd' copy.
>>> dic := Dictionary new.
>>> dic at: key1 put: 1.
>>> dic at: key2 put: 2.
>>> key1 at: 1 put: $z.
>>   dic rehash "synopsis: re-establish hash invariants, if any ".
>>
>>> {dic includesKey: key1.
>>> dic keys includes: key1.}
>>>
>>> So i propose newbies do not use #at:put: considering the danger about  
>>> Dictionary not finding their keys...
>>  There's no danger with Dictionary not finding its keys, unless you  
>> yourself do not follow the protocol.
>>  Smalltalk has no such problems; developers use #rehash after they  
>> changed the #= of keys in Set and subclasses; and please, don't tell  
>> the newcomers the contrary :)
>>
>
> Agree.
> Thanks for this good lesson based on my so dumb example.
> Wouldn't this deserve a longer (Dictionary comment) ?

You're right, the invariant is *essential* for Set and its subclasses,  
alas no word about it in its class comment. Please open a bug report (with  
severity "text"); current policy is that this then gets included in the  
next release.

>>> That's too much.
>>  No not too much; in other languages (especially the "popular" ones)  
>> you are not even allowed to change you strings-now *that* is too much  
>> ;-)
>>  But in Smalltalk you are supported, right from the beginning; happy  
>> Smalltalking everybody :)
>>  /Klaus
>
> Too much was the idea of forbidding #become: or #at:put: for a wrong  
> reason (Dictionary rehash).
>
> Nicolas


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Recap: How to empty a collection

Klaus D. Witzel
In reply to this post by Nicolas Cellier-3
On Wed, 20 Feb 2008 23:05:47 +0100, nicolas cellier wrote:

> Klaus D. Witzel a écrit :
>> On Wed, 20 Feb 2008 02:01:49 +0100, nicolas cellier wrote:
>>
>>> Some proposed an alternative based on (self removeAll: self), and  
>>> started writing optimized versions of #removeAll:.
>>  No, (anOrderedCollection removeAll: anOrderedCollection) was not  
>> optimized. It had a *very* long known bug, which was fixed. Please do  
>> less mixing of subjects in threads.
>>
>
> OK, I'm extrapolating.

O.K. the fix from OrderedCollection *could* be applied to Set (the fix  
requires #copyEmpty), but see Heap below.

> In this case, while you are at it:
>
> | aSet |
> aSet :='Klaus' asSet.
> aSet removeAll: aSet.
> aSet
>
> | aHeap |
> aHeap := Heap withAll: 'Witzel'.
> aHeap removeAll: aHeap.
> aHeap

Don't use Heap much, it is not very conformant; example: (Heap withAll:  
'array') reject: [:x | x = $r] => an Array. Perhaps people didn't know  
about *all* senders of #species ...

>
> I would have used my name, but it seems i am removeable ;-)
> | aSet |
> aSet :='Cellier' asSet.
> aSet removeAll: aSet.
> aSet
>
> Try with the collection of your choice.
>
> In the mean time, don't use (self removeAll: self)...

One step after the other :) no doubt #removeAll: gets fixed, perhaps in  
the next release?

> Yes i'm mixing threads,should be How to NOT empty a collection ;-)
>
> Nicolas
>
>>> I think our biggest problem is that we have plenty possible ways to do  
>>> it... Finding a balance between genericity and efficiency...
>>  No, more correctness at the price of less efficiency :)
>>
>>> Nicolas
>
> Agree on this one.
> Then allow removeAllSuchThat: as default implementation.
>
> Nicolas


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: ordinary #hash and Dictionary [was: Recap: How to empty a collection]

Nicolas Cellier-3
In reply to this post by Klaus D. Witzel
Klaus D. Witzel a écrit :

>> Wouldn't this deserve a longer (Dictionary comment) ?
>
> You're right, the invariant is *essential* for Set and its subclasses,
> alas no word about it in its class comment. Please open a bug report
> (with severity "text"); current policy is that this then gets included
> in the next release.
>

Feel free to correct or complete http://bugs.squeak.org/view.php?id=6942

Maybe a reminder 'See also Set comment in Dictionary comment' would be
welcome.

Cheers

Nicolas

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: ordinary #hash and Dictionary [was: Recap: How to empty a collection]

Klaus D. Witzel
On Thu, 21 Feb 2008 21:44:05 +0100, nicolas cellier wrote:

> Klaus D. Witzel a écrit :
>
>>> Wouldn't this deserve a longer (Dictionary comment) ?
>>  You're right, the invariant is *essential* for Set and its subclasses,  
>> alas no word about it in its class comment. Please open a bug report  
>> (with severity "text"); current policy is that this then gets included  
>> in the next release.
>>
>
> Feel free to correct or complete http://bugs.squeak.org/view.php?id=6942

Done, added the ANSI wording :)

>
> Maybe a reminder 'See also Set comment in Dictionary comment' would be  
> welcome.

Sure.

> Cheers
>
> Nicolas


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
12