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

Frank Shearar frank.shearar at angband.za.org
Tue Nov 2 18:04:11 UTC 2010

On 2010/11/02 19:45, Eliot Miranda wrote:
> Hi Levente,
> On Tue, Nov 2, 2010 at 10:16 AM, Levente Uzonyi <leves at elte.hu
> <mailto: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 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?
> What do others prefer?
> I know, choices, choices :)

I like both, and both are well-entrenched terms in the FP world (fold in 
Haskell, and reduce in Common Lisp, for instance).

One extra datum is that there's already a #reduce (Number>>reduce and 
Float>>reduce) so perhaps #fold: might be a better name just because it 
clashes with nothing in Trunk.


More information about the Squeak-dev mailing list