<div dir="ltr"><div>You can always write:</div><div><br></div><div>    ^collec inject: 0 into: #+</div><div><br></div><div>or whatever default zero you need:<br></div><div><br></div><div>   ^collec inject: 0@0 into: #+<br></div></div><br><div class="gmail_quote"><div dir="ltr">Le mar. 8 janv. 2019 à 21:18, tim Rowledge <<a href="mailto:tim@rowledge.org">tim@rowledge.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
> On 2019-01-08, at 12:10 PM, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>> wrote:<br>
> <br>
> IIRC we discussed this issue carefully.  The issue was typing.  Clearly one should only be able to compute the sum of a collection of numbers (or things that answer to + and can be an argument to 0 + ...).  So we wanted to check that there was at least one numbers element in the receiver and hence chose that sum should indeed fail for an empty collection.  It still seems like a reasonable choice to me.  see e.g. <a href="http://forum.world.st/squeak-dev-Re-Collection-gt-gt-sum-implementation-td77002.html#a77008" rel="noreferrer" target="_blank">http://forum.world.st/squeak-dev-Re-Collection-gt-gt-sum-implementation-td77002.html#a77008</a><br>
<br>
I'm sure much thought was put into it; it's never easy trying to make really well crafted high-generality code. I certainly see the value for the #reduce: code as a general thing. I always did have a problem with messages like sum, average, median, and so on being implemented for general collections, for exactly the reason you point out - collections aren't all that often of purely numeric things. <br>
<br>
In the particular case I stumbled over, the usage of #sum carries way too many assumptions and provides no way to recover from them. Indeed the entire algorithm in that part of the code collapses with a big "oh bugger".<br>
<br>
tim<br>
--<br>
tim Rowledge; <a href="mailto:tim@rowledge.org" target="_blank">tim@rowledge.org</a>; <a href="http://www.rowledge.org/tim" rel="noreferrer" target="_blank">http://www.rowledge.org/tim</a><br>
Useful Latin Phrases:- Sentio aliquos togatos contra me conspirare = I think some people in togas are plotting against me.<br>
<br>
<br>
<br>
</blockquote></div>