[squeak-dev] Collection>>sum implementation
Tony Garnock-Jones
tonyg at lshift.net
Mon Aug 11 16:09:57 UTC 2008
Tony Garnock-Jones wrote:
> a definition for an
> appropriate zero
Another option is to make zero in Smalltalk inhabit multiple types! (In
a similar way to the way nil in Smalltalk inhabits multiple types) Then,
sum
^ self inject: 0 into: [:accum :each | accum + each]
...would work, so long as the elements treated 0 as a zero for #+.
More information about the Squeak-dev
mailing list
|