[squeak-dev] Collection>sum fails on empty collection
nicolas.cellier.aka.nice at gmail.com
Tue Jan 8 21:54:14 UTC 2019
You can always write:
^collec inject: 0 into: #+
or whatever default zero you need:
^collec inject: 0 at 0 into: #+
Le mar. 8 janv. 2019 à 21:18, tim Rowledge <tim at rowledge.org> a écrit :
> > On 2019-01-08, at 12:10 PM, Eliot Miranda <eliot.miranda at gmail.com>
> > 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.
> 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 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev