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