[squeak-dev] Re: Collection>>sum implementation

Randal L. Schwartz merlyn at stonehenge.com
Tue Aug 12 17:36:52 UTC 2008


>>>>> "Ramon" == Ramon Leon <ramon.leon at allresnet.com> writes:

Ramon> +1 on this, most idiomatic looking solution so far since using ifNil: is a
Ramon> common idiom for defaulting a value.  It also properly handles collections
Ramon> which might contain nil's by skipping over the nil while summing without
Ramon> assuming any ordering by trying to use #first.

Not really.  It actually makes nil a special positional value.

{ nil . 3 } sum => 3
{ 3 . nil } sum => "can't add 3 + nil"

I don't like it from that perspective.  Any/all leading nils would
be stripped, but other nils would be included.  But what does "leading"
mean in an UnorderedCollection?  Exactly.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion



More information about the Squeak-dev mailing list