[squeak-dev] Collection's #fold: vs #reduce:

Levente Uzonyi leves at elte.hu
Tue Nov 2 18:31:57 UTC 2010


On Tue, 2 Nov 2010, Eliot Miranda wrote:

> Hi Levente,
>
> On Tue, Nov 2, 2010 at 10:16 AM, Levente Uzonyi <leves at elte.hu> wrote:
>
>> Hi,
>>
>> we have these two methods which do exactly the same thing. #reduce: was
>> added by Andreas during the developement of Squeak 4.1. #fold was added by
>> Eliot for Cog VMMaker compatibility. One of them is superfluous. I can image
>> the following solutions:
>>
>> 1) Replace senders of #fold: in VMMaker to use #reduce:, and remove #fold:
>> from the image.
>>
>> 2) Replace #fold:'s implementation to self reduce: aBlock. I benchmarked
>> the two methods and #reduce: is a bit faster on CogVM. There's no difference
>> on SqueakVM.
>>
>
> I noticed the same thing.  I prefer the fold: implementation so I'm bummed
> it's slightly slower ;)  Personally I like fold: as a name (it's shorter and

The difference is about 1%, but it's reproducible. And yes, the 
implementation of #fold: is a bit nicer. :)

> more cuddly) and since we don't have map: (we have collect:) I don't find
> the need to use reduce: compelling.  But that's my preference.  I won't
> object if you replace fold: with reduce:/  I do note that Gilad used fold:
> in Newspeak.
>
> What do you prefer?

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 "Why isn't there a
method for folding in Squeak?".


Levente

>
> What do others prefer?
>
> I know, choices, choices :)
>
> best
> Eliot
>
>
>
>>
>>
>> Cheers,
>> Levente
>>
>>
>



More information about the Squeak-dev mailing list