[squeak-dev] Collection>sum fails on empty collection

tim Rowledge tim at rowledge.org
Tue Jan 8 20:18:51 UTC 2019



> On 2019-01-08, at 12:10 PM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> 
> 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. http://forum.world.st/squeak-dev-Re-Collection-gt-gt-sum-implementation-td77002.html#a77008

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. 

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".

tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Useful Latin Phrases:- Sentio aliquos togatos contra me conspirare = I think some people in togas are plotting against me.




More information about the Squeak-dev mailing list