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

Eliot Miranda eliot.miranda at gmail.com
Tue Jan 8 20:10:22 UTC 2019


Hi Tim,

On Tue, Jan 8, 2019 at 11:36 AM tim Rowledge <tim at rowledge.org> wrote:

> #() sum -> errorEmptyCollection.
>
> #sum uses #reduce: and I can see why #reduce might consider an empty
> collection an error - but I also see that #sum of an empty collection
> probably ought to be 0, at least in a lot of cases. And I'd note that using
> a simple #inject:into: - in the case of a million item Array, at least -
> took about 60% of the time of the current #sum.
>
> Why did this come up? In an MVC Project I tested
>   PluggableFileList getFolderDialog openLabel: 'foo'
> whilst seeing if PluggableFileList had any uses. It turns out that
> building a PluggableFileList in MVC doesn't work. Somewhere we end up
> trying to build a pluggablepanel with no children, which makes the logic in
> MVCToolBuilder>>setLayout:in: get upset. I don't care enough about making
> MVC stuff work to be willing to spend time on that.
>

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

_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190108/b3ccae13/attachment.html>


More information about the Squeak-dev mailing list