[ANSI-Smalltalk] Behaviour of #collect:
Eliot Miranda
eliot.miranda at gmail.com
Mon Sep 22 17:39:05 BST 2008
What about
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.openskills.org/pipermail/ansi-smalltalk/attachments/20080922/6a792b9d/attachment.htm
More information about the ANSI-Smalltalk
mailing list