help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Re: Dictionary>>#addAll: fails


From: Paolo Bonzini
Subject: [Help-smalltalk] Re: Dictionary>>#addAll: fails
Date: Mon, 26 Mar 2007 09:21:14 +0200
User-agent: Thunderbird 1.5.0.10 (Macintosh/20070221)

Stephen Compall wrote:
> On Fri, 2007-03-23 at 15:26 +0100, Paolo Bonzini wrote:
>> One possibility could be to extend the {...} syntax to something
>> like "OrderedCollection {...}", "Dictionary {...}", and have it send
>> messages like "#braceWithAll:".  Then you would have:
> 
> I would rather leave the syntax alone and just add the protocol:

What about adding #from: ?  I want it to be terse and still clear if
possible.

>>      Dictionary >> braceWithAll: x
>>          | dict |
>>          dict := self new: x size * 2.
> 
> I like these as they are, except for the * 2 in Dictionary's method.

Well, it's there because a hash table needs more room than it has
elements.  In fact I'm about to add

     HashedCollection >> withAll: x
         | result |
         result := self new: x size * 2.
         result addAll: x.
         ^result

It does not apply to with:with: and friends only because of

new: anInteger
    "Answer a new instance of the receiver with the given size"
    | realSize |
    realSize := 8 max: anInteger.
    ...
    ^(self primNew: realSize) initialize: realSize

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]