<br><br><div class="gmail_quote">On Tue, Nov 2, 2010 at 11:31 AM, Levente Uzonyi <span dir="ltr">&lt;<a href="mailto:leves@elte.hu">leves@elte.hu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Tue, 2 Nov 2010, Eliot Miranda wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Levente,<br>
<br>
On Tue, Nov 2, 2010 at 10:16 AM, Levente Uzonyi &lt;<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>&gt; wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
we have these two methods which do exactly the same thing. #reduce: was<br>
added by Andreas during the developement of Squeak 4.1. #fold was added by<br>
Eliot for Cog VMMaker compatibility. One of them is superfluous. I can image<br>
the following solutions:<br>
<br>
1) Replace senders of #fold: in VMMaker to use #reduce:, and remove #fold:<br>
from the image.<br>
<br>
2) Replace #fold:&#39;s implementation to self reduce: aBlock. I benchmarked<br>
the two methods and #reduce: is a bit faster on CogVM. There&#39;s no difference<br>
on SqueakVM.<br>
<br>
</blockquote>
<br>
I noticed the same thing.  I prefer the fold: implementation so I&#39;m bummed<br>
it&#39;s slightly slower ;)  Personally I like fold: as a name (it&#39;s shorter and<br>
</blockquote>
<br></div>
The difference is about 1%, but it&#39;s reproducible. And yes, the implementation of #fold: is a bit nicer. :)</blockquote><div><br></div><div>The difference is due to the instantiation &quot;Object new&quot;, and instantiation is slow on the current Cog because I haven&#39;t implemented the instantiation primitives in machine code, and this limitation is hopefully temporary.  So you might leave it be.  However, changing the code to use {} for teh instantiation speeds things up markedly:</div>
<div><br></div><div>Collection&gt;&gt;newFold: binaryBlock</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>| firstValue nextValue |</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>firstValue := nextValue := {}.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>self do:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>[:each |</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>nextValue := firstValue == nextValue</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                </span>ifTrue: [each]</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>ifFalse: [binaryBlock value: nextValue value: each]].</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>^nextValue == firstValue</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>ifTrue: [self errorEmptyCollection]</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [nextValue]</div>
<div><br></div><div><div>| c r |</div><div>c := #(&#39;if&#39; &#39;it&#39; &#39;is&#39; &#39;to&#39; &#39;be&#39; &#39;it&#39; &#39;is&#39; &#39;up&#39; &#39;to&#39; &#39;me&#39;).</div><div>{ Time millisecondsToRun: [1 to: 1000000 do: [:i| c fold: [:a :b | a, &#39; &#39;, b]]].</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>Time millisecondsToRun: [1 to: 1000000 do: [:i| c newFold: [:a :b | a, &#39; &#39;, b]]].</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Time millisecondsToRun: [1 to: 1000000 do: [:i| c reduce: [:a :b | a, &#39; &#39;, b]]] }</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div>#(5076 5008 5052)</div><div><br></div><div><br></div><div>| c |</div><div>
c := #(&#39;if&#39;).</div><div>{ Time millisecondsToRun: [1 to: 1000000 do: [:i| c fold: [:a :b | a, &#39; &#39;, b]]].</div><div>   Time millisecondsToRun: [1 to: 1000000 do: [:i| c newFold: [:a :b | a, &#39; &#39;, b]]].</div>
<div>   Time millisecondsToRun: [1 to: 1000000 do: [:i| c reduce: [:a :b | a, &#39; &#39;, b]]] }</div><div> #(247 226 220)</div></div><div><br></div><div><br></div><div>(N.B.  the above are rough measurements!!).</div><div>
<br></div><div>So how about changing fold: to replace Object new with {} and keep it?</div><div><br></div><div><br></div><div>2˘</div><div>Eliot</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
more cuddly) and since we don&#39;t have map: (we have collect:) I don&#39;t find<br>
the need to use reduce: compelling.  But that&#39;s my preference.  I won&#39;t<br>
object if you replace fold: with reduce:/  I do note that Gilad used fold:<br>
in Newspeak.<br>
<br>
What do you prefer?<br>
</blockquote>
<br></div>
I prefer the second option, because both names are widely used, but some people are only aware of the one which their previously used languages have. So this way we can avoid questions like &quot;Why isn&#39;t there a<br>

method for folding in Squeak?&quot;.<br><font color="#888888">
<br>
<br>
Levente</font><div><div></div><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
What do others prefer?<br>
<br>
I know, choices, choices :)<br>
<br>
best<br>
Eliot<br>
<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
Cheers,<br>
Levente<br>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br>