[ANSI-Smalltalk] Behaviour of #collect:

Andres Valloud andres.valloud at gmail.com
Thu Sep 25 10:40:20 BST 2008


Or this?...

'abc' collect: [:x | x codePoint] into: Array

Andres.

On Mon, Sep 22, 2008 at 9:40 AM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> what about
>      Collection class collect: aBlock from: aCollection
> e.g.
>      Array collect: [:each | each codePoint] from: 'abc'
> ?
>
> On Sun, Sep 21, 2008 at 11:13 PM, Richard A. O'Keefe <ok at cs.otago.ac.nz>
> wrote:
>>
>> Pretty much every Smalltalk I've tried has failed this test:
>>
>>        'abc' collect: [:each | each codePoint]
>>
>> (or the equivalent using some non-standard replacement for
>> #codePoint).  It seems obvious to me that this should make
>> a "best effort" attempt to collect the results of the block,
>> just as
>>
>>        (97 to: 99) collect: [:each | Character codePoint: each]
>>
>> doesn't complain that an Interval can't store characters.
>> I have on occasion reported this as a bug and provided code to
>> make it work more or less as expected.
>>
>> My own library has in each collection class a class method
>>        SomeCollection withAll: aCollection collect: aBlock
>> so that I could hack this particular example using
>>        Array withAll: 'abc' collect: [:each | each codePoint]
>> or even
>>        ByteArray withAll: 'abc'
>>                  collect: [:each | each codePoint].
>>
>> Would adding #withAll:collect: to every class that has #withAll:
>> be considered a good move?
>>
>> What exactly should #collect: do when sent to an object that
>> belongs to a class whose instances cannot hold the results that
>> the block returns?
>>
>> By the way, this particular example was not one constructed to
>> break things; it's a simplified version of something that came up
>> in real code.
>>
>>
>> _______________________________________________
>> ANSI-Smalltalk mailing list
>> ANSI-Smalltalk at lists.openskills.org
>> http://lists.openskills.org/cgi-bin/mailman/listinfo/ansi-smalltalk
>
>
> _______________________________________________
> ANSI-Smalltalk mailing list
> ANSI-Smalltalk at lists.openskills.org
> http://lists.openskills.org/cgi-bin/mailman/listinfo/ansi-smalltalk
>
>



More information about the ANSI-Smalltalk mailing list