[squeak-dev] Re: Re: Why is Heap>>#species => Array?

Klaus D. Witzel klaus.witzel at cobss.com
Fri Feb 22 23:12:02 UTC 2008


On Fri, 22 Feb 2008 23:25:54 +0100, Andrew P. Black wrote:

>
> On 21 Feb 2008, at 23:49, Klaus D. Witzel wrote:
>
>> On Fri, 22 Feb 2008 06:22:32 +0100, Paolo Bonzini wrote:
>>
>>> Klaus D. Witzel wrote:
>>>> Subject line says it all, check yourself,
>>>>  (Heap withAll: 'array') reject: [:x | x = $r]
>>>>  What's the rationale (there's no doc, no comment)? Archive shows  
>>>> that #species was changed to fix another (anonymous) bug but, this  
>>>> way the senders of #species can impossibly do what Smalltalk users  
>>>> expect from the collection hierarchy (and there is #asArray ...)
>>>
>
> Klaus asked if we had any insights on this during the reengineering of  
> the collection hierarchy.  The answer is yes, although my recollection  
> of them may be imperfect.
[...snipped a lot of insightful text...]
> I think that after we were done, we came to the conclusion that the kind  
> of collection that results from a collect: ought to be a parameter to  
> the collect.  For example, if I do a collect: over an IdentitySet,  
> should the result be another IdentitySet, a Set, or an Array?  Well, it  
> depends on the function that I'm applying: there is no one right  
> answer.  Similarly, with collect: on a SortedCollection,  should the  
> result be an OrderedCollection, an Array, or a new SortedCollection?  If  
> the latter, with what sort block?    One way to do this is to have a  
> #collect:into: method where the second argument is a collection into  
> which the new elements will be added.  It's not even necessary for it to  
> be empty!   Another possibility would be to provide as argument a block  
> that does the adding ... this starts to look very much like #do:  So, we  
> never implemented those variants.

Yeah, #collect:into: would give control over the resulting species to the  
developer; but I think it would be adopted rather reluctantly for existing  
apps (of course today's #collect: etc implementation could benefit from  
such factorization).

Thank you for the feedback !

/Klaus

> 	Andrew
>




More information about the Squeak-dev mailing list