[squeak-dev] Re: Collection>>sum implementation
Jason Johnson
jason.johnson.081 at gmail.com
Tue Aug 12 06:30:51 UTC 2008
On Mon, Aug 11, 2008 at 6:21 PM, Paolo Bonzini <bonzini at gnu.org> wrote:
>>> This method is called #fold: in VisualWorks, GNU Smalltalk and others.
>>>
>>> Paolo
>>
>> Ah ok. It's called reduce in python and Lisp, and that's also what
>> Lukas named it in his package.
>
> I think #fold: is the Haskell name (they have both foldl and foldr), but
> probably it comes from somewhere else. Eliot should know...
>
> Paolo
I don't know if Haskell has what I'm calling the "reduce operator".
They have foldl and foldr, which are like #inject:into: but have a
slightly different behavior. The easiest way to understand it is to
imagine a list; #(1 2 3) as:
1 : 2 : 3 : []
where [] is an empty list and : is an operator the appends the left
side to the right. So foldl and foldr both replace the : with the
function they are passed and the [] with the initial value they are
passed. The difference between the two is which way they then
resolve. So if they did provide a "resolve" operation (i.e. take one
less value and use the first element of the list as the "initial
value") I would expect there to be two of them.
#inject:into: behaves like a right fold (reduction moves from left to
right) but with the [] on the front of the list instead of the end.
More information about the Squeak-dev
mailing list
|