[squeak-dev] Re: #collect: on strings

Damien Cassou damien.cassou at gmail.com
Wed Jun 25 20:37:52 UTC 2008


On Wed, Jun 25, 2008 at 4:59 PM, Klaus D. Witzel <klaus.witzel at cobss.com> wrote:
> On Wed, 25 Jun 2008 16:48:17 +0200, Damien Cassou wrote:
>
>> On Wed, Jun 25, 2008 at 4:43 PM, Klaus D. Witzel <klaus.witzel at cobss.com>
>> wrote:
>>>
>>> On Wed, 25 Jun 2008 10:46:49 +0200, Damien Cassou wrote:
>>>
>>>> On Wed, Jun 25, 2008 at 9:39 AM, cdrick wrote:
>>>>>
>>>>> (Array withAll: 'something') collect: [ :letter | letter isVowel ].
>>>>> #(false true false true false false true false false)
>>>>
>>>> I did that
>>>>
>>>> 'something' asArray collect: [ :letter | letter isVowel ].
>>>>
>>>> do get the desired behavior. However, it is not intuitive to me.
>>>
>>> I agree, in some cases I want to tell #collect: what #species to use (OT:
>>> and inspired by the LambdaMessageSend package, I have made a snippet
>>> which
>>> does feed #species into otherwise unchanged #collect:).
>>>
>>> But what do *you* expect to happen with your original expression, mind to
>>> share?
>>
>> A collection of boleans.
>
> Well, let's look at #collect: it has a block as argument. Because of this
> object orientedness, the implementor of #collect: cannot know what sort of
> values the block will return in the future, no?
>
> How about this, let #collect: always collect into anOrderedCollection, then
> it can eventually
>
>  ^ anOrderedCollection coercedWith: self

What does #coercedWith: mean? I would agree if it is something like:
"try to make a collection of the same species as the parameter with
the content of the receiver and if it is not possible, return the
receiver"




-- 
Damien Cassou
Peter von der Ahé: «I'm beginning to see why Gilad wished us good
luck». (http://blogs.sun.com/ahe/entry/override_snafu)



More information about the Squeak-dev mailing list