<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Hi Luciano,<br>
<br>
I agree that restricting #sum: to be used with a block that is a
function is reasonable, and probably best.<br>
<br>
But I disagree about changing a collection while iterating it. I
have often wanted a collection that could be modified while
iterating it. And, given how much time I've spent writing stuff
that has to work in a multi-threaded environment, I've probably
implemented that sort of collection at least once. My idea of
desirable semantics for this kind of collection are:<br>
1) The iteration <i>will</i> include each element that is present
throughout the iteration.<br>
2) It is <i>unpredictable</i> whether any elements added or
removed during the iteration are included in the iteration.<br>
3) The same element (same being equal or identical, depending on
the collection) will appear at most once in the iteration.<br>
<br>
There are a number of cases where this is useful. <br>
<br>
* The iterating thread may want to add or remove elements while it
iterates.<br>
A queue is a simple example of this kind of collection, where the
iterator is unconditionally removing elements as they're iterated,
while some other entity may be concurrently adding elements. This
can be generalized to conditional removal of elements that are
iterated, or conditional adding of elements based on elements
found.<br>
<br>
* Modification of the collection and iteration of the collection
might happen in separate threads. There are times when a "more or
less up-to-date" iteration of the contents is fine.<br>
<br>
Regards,<br>
-Martin <br>
<br>
On 11/2/22 21:57, Luciano Notarfrancesco via Cuis-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAL5GDyp8UN49DRG5uvkXMigiv9riuL92Gah4CMk4moByP1FMow@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="auto">Yes, the method assumes the block is a function
(it maps one element to only one value). We talked about this
here a couple of times. The Collection protocol is very
“functional”, specially messages like #collect:, #select:,
#detect:, etc, and using them with blocks that are functions is
the most natural way to use them, and I don’t think we loose
anything by making the assumption that the blocks for these
messages are functions.</div>
<div dir="auto">Moreover, the whole point of Bag is to be able to
efficiently store elements with lots of repetitions, possibly
millions of repetitions that otherwise wouldn’t even fit in
memory. If #sum: iterated over all the repetitions it would
defeat the original purpose of Bag. And I argue that this is not
necessary because no one would ever call #sum: with a block that
is not a function, at least I never had the need to do that, and
it feels unnatural to use #sum: in that way and I’d use #do:
instead.</div>
<div dir="auto">If you think this assumption is strange, think
about all the other assumptions that collections make. For
example, you cannot change a collection while you’re iterating
it. It would just feel wrong to change a collection while you
iterate it, we don’t need to try to support that because who
would do that?</div>
<div dir="auto"><br>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">On Thu, 3 Nov 2022 at 03:12 Hernán Wilkinson <<a
href="mailto:hernan.wilkinson@10pines.com"
moz-do-not-send="true" class="moz-txt-link-freetext">hernan.wilkinson@10pines.com</a>>
wrote:<br>
</div>
<div>
<div class="gmail_quote">
<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)">
<div dir="ltr">How does that optimization work?
<div>Because I thought about evaluating the block and
multiplying that for the number of elements, but that
makes sense if the block returns always the same value
por the same element, if it does not then it will not
work...</div>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Nov 2, 2022 at
3:24 PM Juan Vuletich <<a href="mailto:juan@cuis.st"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">juan@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)">
<div bgcolor="#ffffff"> On 11/1/2022 11:23 PM, Hernán
Wilkinson via Cuis-dev wrote:
<blockquote type="cite">
<div dir="ltr">yeap, the current implementation is
not correct.
<div>Juan, attached is a change set that fixes it
and another with the related tests.</div>
<div><br>
</div>
<div>Cheers!</div>
<div>Hernan.</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Nov 1,
2022 at 3:39 AM Luciano Notarfrancesco <<a
href="mailto:luchiano@gmail.com"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">luchiano@gmail.com</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)">
<div dir="auto">I’m afk right now so I cannot
check, but it sounds like I made a mistake. Of
course it should be the value of aBlock at
each element times the number of occurrences.</div>
<div><br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, 1
Nov 2022 at 07:33 Hernán Wilkinson <<a
href="mailto:hernan.wilkinson@10pines.com" target="_blank"
moz-do-not-send="true"
class="moz-txt-link-freetext">hernan.wilkinson@10pines.com</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)">
<div dir="ltr">Hi,
<div> the implementation of
Bag>>#sum: aBlock ifEmpty:
emptyBlock does not use the parameter
aBlock at all and assumes that each of
the elements answers the message * </div>
<div> <a class="gmail_plusreply"
id="m_-8793636495669467945m_7503398456341899303m_-3423588523307269653m_4335152602574426633plusReplyChip-0"
href="mailto:luchiano@gmail.com"
target="_blank"
moz-do-not-send="true">@Luciano
Notarfrancesco</a> the
implementation is yours and it is very
new? Is there a reason you did that
way? </div>
<div><br>
</div>
<div>Thanks</div>
<div>Hernan</div>
</div>
<div dir="ltr">
<div><br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">
<div dir="ltr">
<div>
<div dir="ltr">
<div style="font-size:small">
<div dir="ltr">
<div dir="ltr">
<div
style="font-size:12.8px"><span
style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong
style="font-family:tahoma,sans-serif"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif"><span
style="font-weight:bold;font-family:tahoma,sans-serif">Hernán
Wilkinson</span><br>
Agile Software
Development,
Teaching &
Coaching</span></font></span></span></strong></span></div>
<div
style="font-size:12.8px"><span
style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong
style="font-family:tahoma,sans-serif"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif">Phone: +54-011</span></font></span></span></strong></span><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)" size="2"
face="tahoma,
sans-serif">-4893-2057</font></div>
<div
style="font-size:12.8px"><strong
style="font-family:tahoma,sans-serif;font-size:xx-small"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif">Twitter:
@HernanWilkinson</span></font></span></span></strong></div>
<div
style="font-size:12.8px"><span
style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong
style="font-family:tahoma,sans-serif"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif">site: <a
href="http://www.10pines.com/"
style="font-family:tahoma,sans-serif;color:rgb(17,65,112)"
target="_blank"
moz-do-not-send="true">http://www.10Pines.com</a></span></font></span></span></strong></span></div>
<div
style="font-size:12.8px"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)" face="tahoma,
sans-serif"><span
style="border-collapse:collapse;font-family:tahoma,sans-serif">Address:
Alem 896</span></font>,
Floor 6, Buenos Aires,
Argentina</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">
<div dir="ltr">
<div>
<div dir="ltr">
<div style="font-size:small">
<div dir="ltr">
<div dir="ltr">
<div style="font-size:12.8px"><span
style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong
style="font-family:tahoma,sans-serif"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif"><span
style="font-weight:bold;font-family:tahoma,sans-serif">Hernán Wilkinson</span><br>
Agile Software
Development, Teaching
& Coaching</span></font></span></span></strong></span></div>
<div style="font-size:12.8px"><span
style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong
style="font-family:tahoma,sans-serif"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif">Phone:
+54-011</span></font></span></span></strong></span><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)" size="2"
face="tahoma, sans-serif">-4893-2057</font></div>
<div style="font-size:12.8px"><strong
style="font-family:tahoma,sans-serif;font-size:xx-small"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif">Twitter:
@HernanWilkinson</span></font></span></span></strong></div>
<div style="font-size:12.8px"><span
style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong
style="font-family:tahoma,sans-serif"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif">site: <a
href="http://www.10pines.com/"
style="font-family:tahoma,sans-serif;color:rgb(17,65,112)"
target="_blank"
moz-do-not-send="true">http://www.10Pines.com</a></span></font></span></span></strong></span></div>
<div style="font-size:12.8px"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
face="tahoma, sans-serif"><span
style="border-collapse:collapse;font-family:tahoma,sans-serif">Address:
Alem 896</span></font>, Floor 6,
Buenos Aires, Argentina</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
Hi Hernán,<br>
<br>
Your fix disables the optimization Luciano did. I
chose to fix Luciano's code. Did the same for
#product: (same bug). Integrated your tests, and added
another one for #product:<br>
<br>
Thanks,<br>
<pre cols="72" style="font-family:monospace">--
Juan Vuletich
<a href="http://cuis.st" target="_blank" style="font-family:monospace" moz-do-not-send="true">cuis.st</a>
<a href="http://github.com/jvuletich" target="_blank" style="font-family:monospace" moz-do-not-send="true">github.com/jvuletich</a>
<a href="http://researchgate.net/profile/Juan-Vuletich" target="_blank" style="font-family:monospace" moz-do-not-send="true">researchgate.net/profile/Juan-Vuletich</a>
<a href="http://independent.academia.edu/JuanVuletich" target="_blank" style="font-family:monospace" moz-do-not-send="true">independent.academia.edu/JuanVuletich</a>
<a href="http://patents.justia.com/inventor/juan-manuel-vuletich" target="_blank" style="font-family:monospace" moz-do-not-send="true">patents.justia.com/inventor/juan-manuel-vuletich</a>
<a href="http://linkedin.com/in/juan-vuletich-75611b3" target="_blank" style="font-family:monospace" moz-do-not-send="true">linkedin.com/in/juan-vuletich-75611b3</a>
<a href="http://twitter.com/JuanVuletich" target="_blank" style="font-family:monospace" moz-do-not-send="true">twitter.com/JuanVuletich</a></pre>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">
<div dir="ltr">
<div>
<div dir="ltr">
<div style="font-size:small">
<div dir="ltr">
<div dir="ltr">
<div style="font-size:12.8px"><span
style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong
style="font-family:tahoma,sans-serif"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)" size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif"><span
style="font-weight:bold;font-family:tahoma,sans-serif">Hernán Wilkinson</span><br>
Agile Software Development,
Teaching & Coaching</span></font></span></span></strong></span></div>
<div style="font-size:12.8px"><span
style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong
style="font-family:tahoma,sans-serif"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)" size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif">Phone:
+54-011</span></font></span></span></strong></span><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)" size="2"
face="tahoma, sans-serif">-4893-2057</font></div>
<div style="font-size:12.8px"><strong
style="font-family:tahoma,sans-serif;font-size:xx-small"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)" size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif">Twitter:
@HernanWilkinson</span></font></span></span></strong></div>
<div style="font-size:12.8px"><span
style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong
style="font-family:tahoma,sans-serif"><span
style="font-size:8pt;font-family:tahoma,sans-serif"><span
style="font-size:small;font-family:tahoma,sans-serif"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)" size="2"><span
style="font-weight:normal;font-family:tahoma,sans-serif">site: <a
href="http://www.10pines.com/"
style="font-family:tahoma,sans-serif;color:rgb(17,65,112)"
target="_blank"
moz-do-not-send="true">http://www.10Pines.com</a></span></font></span></span></strong></span></div>
<div style="font-size:12.8px"><font
style="font-family:tahoma,sans-serif;color:rgb(0,0,0)"
face="tahoma, sans-serif"><span
style="border-collapse:collapse;font-family:tahoma,sans-serif">Address:
Alem 896</span></font>, Floor 6, Buenos
Aires, Argentina</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
</blockquote>
<br>
</body>
</html>