[squeak-dev] The Inbox: Collections-ul.587.mcz

Eliot Miranda eliot.miranda at gmail.com
Wed Nov 19 00:11:11 UTC 2014


On Tue, Nov 18, 2014 at 3:08 PM, Levente Uzonyi <leves at elte.hu> wrote:

> Hi All,
>
> The reason why I put this into The Inbox instead of The Trunk is that it
> changes the behavior of #sum when the Interval is empty.
> The current implementation raises an error - which is correct for a
> Collection which may contain any object - but I think for Intervals the
> preferred behavior is to return 0. Any objections?


I want to add a non-objection, an anti-objection, or whatever will cause
you to put this in trunk ;-)  Clearly the bug is in the original sum.  It
should read

sum
"Compute the sum of all the elements in the receiver"

^self isEmpty ifTrue: [0] ifFalse: [self reduce:[:a :b| a + b]]

Levente
>
>
> On Tue, 18 Nov 2014, commits at source.squeak.org wrote:
>
>  A new version of Collections was added to project The Inbox:
>> http://source.squeak.org/inbox/Collections-ul.587.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Collections-ul.587
>> Author: ul
>> Time: 18 November 2014, 11:53:01.797 pm
>> UUID: 30ba8551-0c97-4cf5-b830-9386f272b8d2
>> Ancestors: Collections-ul.586
>>
>> Optimized Interval >> #sum.
>>
>> =============== Diff against Collections-ul.586 ===============
>>
>> Item was added:
>> + ----- Method: Interval>>sum (in category 'accessing') -----
>> + sum
>> +       "Optimized version. Use the sum(n*i - k, i=a..b) = -1/2*(a - b -
>> 1)*(n * (a + b) - 2 * k) equation with a = 1, n = step, b = self size."
>> +
>> +       | b |
>> +       b := self size.
>> +       ^b * ((b + 1) * step - (step - start * 2)) / 2!
>>
>>
>>
>>
>


-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20141118/7442553c/attachment.htm


More information about the Squeak-dev mailing list