<div dir="auto">Yes. Actually it assumes slightly less, it assumes the values of the block can be added (and thus multiplied by a natural number n, which means adding it to itself n times and it is always possible and should be implemented as #*). The main use of #sum: is with blocks that evaluate to Numbers, but it works for more general objects.</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 3 Nov 2022 at 12:25 Andres Valloud via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">The message #sum: seemingly assumes the presence of a ring where the <br>
messages + and * are coordinated.<br>
<br>
On 11/2/22 9:57 PM, Luciano Notarfrancesco via Cuis-dev wrote:<br>
> Yes, the method assumes the block is a function (it maps one element to <br>
> only one value). We talked about this here a couple of times. The <br>
> Collection protocol is very “functional”, specially messages like <br>
> #collect:, #select:, #detect:, etc, and using them with blocks that are <br>
> functions is the most natural way to use them, and I don’t think we <br>
> loose anything by making the assumption that the blocks for these <br>
> messages are functions.<br>
> Moreover, the whole point of Bag is to be able to efficiently store <br>
> elements with lots of repetitions, possibly millions of repetitions that <br>
> otherwise wouldn’t even fit in memory. If #sum: iterated over all the <br>
> repetitions it would defeat the original purpose of Bag. And I argue <br>
> that this is not necessary because no one would ever call #sum: with a <br>
> block that is not a function, at least I never had the need to do that, <br>
> and it feels unnatural to use #sum: in that way and I’d use #do: instead.<br>
> If you think this assumption is strange, think about all the other <br>
> assumptions that collections make. For example, you cannot change a <br>
> collection while you’re iterating it. It would just feel wrong to change <br>
> a collection while you iterate it, we don’t need to try to support that <br>
> because who would do that?<br>
> <br>
> <br>
> On Thu, 3 Nov 2022 at 03:12 Hernán Wilkinson <br>
> <<a href="mailto:hernan.wilkinson@10pines.com" target="_blank">hernan.wilkinson@10pines.com</a> <mailto:<a href="mailto:hernan.wilkinson@10pines.com" target="_blank">hernan.wilkinson@10pines.com</a>>> wrote:<br>
> <br>
>     How does that optimization work?<br>
>     Because I thought about evaluating the block and multiplying that<br>
>     for the number of elements, but that makes sense if the block<br>
>     returns always the same value por the same element, if it does not<br>
>     then it will not work...<br>
> <br>
> <br>
>     On Wed, Nov 2, 2022 at 3:24 PM Juan Vuletich <<a href="mailto:juan@cuis.st" target="_blank">juan@cuis.st</a><br>
>     <mailto:<a href="mailto:juan@cuis.st" target="_blank">juan@cuis.st</a>>> wrote:<br>
> <br>
>         __<br>
>         On 11/1/2022 11:23 PM, Hernán Wilkinson via Cuis-dev wrote:<br>
>>         yeap, the current implementation is not correct.<br>
>>         Juan, attached is a change set that fixes it and another with<br>
>>         the related tests.<br>
>><br>
>>         Cheers!<br>
>>         Hernan.<br>
>><br>
>>         On Tue, Nov 1, 2022 at 3:39 AM Luciano Notarfrancesco<br>
>>         <<a href="mailto:luchiano@gmail.com" target="_blank">luchiano@gmail.com</a> <mailto:<a href="mailto:luchiano@gmail.com" target="_blank">luchiano@gmail.com</a>>> wrote:<br>
>><br>
>>             I’m afk right now so I cannot check, but it sounds like I<br>
>>             made a mistake. Of course it should be the value of aBlock<br>
>>             at each element times the number of occurrences.<br>
>><br>
>>             On Tue, 1 Nov 2022 at 07:33 Hernán Wilkinson<br>
>>             <<a href="mailto:hernan.wilkinson@10pines.com" target="_blank">hernan.wilkinson@10pines.com</a><br>
>>             <mailto:<a href="mailto:hernan.wilkinson@10pines.com" target="_blank">hernan.wilkinson@10pines.com</a>>> wrote:<br>
>><br>
>>                 Hi,<br>
>>                  the implementation of Bag>>#sum: aBlock ifEmpty:<br>
>>                 emptyBlock does not use the parameter aBlock at all<br>
>>                 and assumes that each of the elements answers the<br>
>>                 message *<br>
>>                 @Luciano Notarfrancesco<br>
>>                 <mailto:<a href="mailto:luchiano@gmail.com" target="_blank">luchiano@gmail.com</a>> the implementation is<br>
>>                 yours and it is very new? Is there a reason you did<br>
>>                 that way?<br>
>><br>
>>                 Thanks<br>
>>                 Hernan<br>
>><br>
>><br>
>>                 -- <br>
>>                 *Hernán Wilkinson<br>
>>                 Agile Software Development, Teaching & Coaching*<br>
>>                 *Phone: +54-011*-4893-2057<br>
>>                 *Twitter: @HernanWilkinson*<br>
>>                 *site: <a href="http://www.10Pines.com" rel="noreferrer" target="_blank">http://www.10Pines.com</a> <<a href="http://www.10pines.com/" rel="noreferrer" target="_blank">http://www.10pines.com/</a>>*<br>
>>                 Address: Alem 896, Floor 6, Buenos Aires, Argentina<br>
>><br>
>><br>
>><br>
>>         -- <br>
>>         *Hernán Wilkinson<br>
>>         Agile Software Development, Teaching & Coaching*<br>
>>         *Phone: +54-011*-4893-2057<br>
>>         *Twitter: @HernanWilkinson*<br>
>>         *site: <a href="http://www.10Pines.com" rel="noreferrer" target="_blank">http://www.10Pines.com</a> <<a href="http://www.10pines.com/" rel="noreferrer" target="_blank">http://www.10pines.com/</a>>*<br>
>>         Address: Alem 896, Floor 6, Buenos Aires, Argentina<br>
> <br>
>         Hi Hernán,<br>
> <br>
>         Your fix disables the optimization Luciano did. I chose to fix<br>
>         Luciano's code. Did the same for #product: (same bug).<br>
>         Integrated your tests, and added another one for #product:<br>
> <br>
>         Thanks,<br>
> <br>
>         -- <br>
>         Juan Vuletich<br>
>         <a href="http://cuis.st" rel="noreferrer" target="_blank">cuis.st</a>  <<a href="http://cuis.st" rel="noreferrer" target="_blank">http://cuis.st</a>><br>
>         <a href="http://github.com/jvuletich" rel="noreferrer" target="_blank">github.com/jvuletich</a>  <<a href="http://github.com/jvuletich" rel="noreferrer" target="_blank">http://github.com/jvuletich</a>><br>
>         <a href="http://researchgate.net/profile/Juan-Vuletich" rel="noreferrer" target="_blank">researchgate.net/profile/Juan-Vuletich</a>  <<a href="http://researchgate.net/profile/Juan-Vuletich" rel="noreferrer" target="_blank">http://researchgate.net/profile/Juan-Vuletich</a>><br>
>         <a href="http://independent.academia.edu/JuanVuletich" rel="noreferrer" target="_blank">independent.academia.edu/JuanVuletich</a>  <<a href="http://independent.academia.edu/JuanVuletich" rel="noreferrer" target="_blank">http://independent.academia.edu/JuanVuletich</a>><br>
>         <a href="http://patents.justia.com/inventor/juan-manuel-vuletich" rel="noreferrer" target="_blank">patents.justia.com/inventor/juan-manuel-vuletich</a>  <<a href="http://patents.justia.com/inventor/juan-manuel-vuletich" rel="noreferrer" target="_blank">http://patents.justia.com/inventor/juan-manuel-vuletich</a>><br>
>         <a href="http://linkedin.com/in/juan-vuletich-75611b3" rel="noreferrer" target="_blank">linkedin.com/in/juan-vuletich-75611b3</a>  <<a href="http://linkedin.com/in/juan-vuletich-75611b3" rel="noreferrer" target="_blank">http://linkedin.com/in/juan-vuletich-75611b3</a>><br>
>         <a href="http://twitter.com/JuanVuletich" rel="noreferrer" target="_blank">twitter.com/JuanVuletich</a>  <<a href="http://twitter.com/JuanVuletich" rel="noreferrer" target="_blank">http://twitter.com/JuanVuletich</a>><br>
> <br>
> <br>
> <br>
>     -- <br>
>     *Hernán Wilkinson<br>
>     Agile Software Development, Teaching & Coaching*<br>
>     *Phone: +54-011*-4893-2057<br>
>     *Twitter: @HernanWilkinson*<br>
>     *site: <a href="http://www.10Pines.com" rel="noreferrer" target="_blank">http://www.10Pines.com</a> <<a href="http://www.10pines.com/" rel="noreferrer" target="_blank">http://www.10pines.com/</a>>*<br>
>     Address: Alem 896, Floor 6, Buenos Aires, Argentina<br>
> <br>
> <br>
-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
</blockquote></div></div>