>>>>> "Ariel" == Ariel Scolnicov <[EMAIL PROTECTED]> writes:

Ariel> reduce needs to be able to take an (optional?) "distinguished element" 
Ariel> to start from.  Consider this:

Ariel>    reduce sum () == 0
Ariel>    reduce times () == 1
Ariel>    reduce catenate () == ''

Ariel> Where do we get the right one from?

In Smalltalk, it's called "inject:into:", and yes, you're providing
both a distinguished "initial" value, and a 2-argument block, along
with the list to process.

"smalltalk: " result _ (1 to: 10) inject: 0 into: [:a :b | a + b] "this is sum"

"perl: "; @result = reduce { $a + $b } 0, (1..10); # sum

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Reply via email to