in reply to Re^7: List::Util::sum() and empty lists... (obvious)
in thread List::Util::sum() and empty lists...

I just wonder what Graham Barr (the original author) has to say about it?

Maybe he did it for consistency. Every function in the module returns undef when given an empty list (except shuffle, which doesn't return a scalar).

Maybe it didn't occur to him to check for that case, since sum is simply sub sum (@) { reduce { $a + $b } @_ }. (While the XS version explicitely returns undef, it probably came after the Perl version.)

Replies are listed 'Best First'.
Re^9: List::Util::sum() and empty lists... (obvious)
by Firefly258 (Beadle) on Dec 05, 2006 at 07:09 UTC
    Maybe. Maybe not. Only he can confirm if it indeed is a genuine oversight or not.

    But since this behaviour is quite clearly documented in the POD for the module, and that the module has been around for almost a decade now, I'm not convinced the behaviour is due to an oversight. But again, the POD could be wrong or script-generated.

    Only Graham or P5P can give us a definite, authoritative statement for the reasons his module behaves the way it does, until then, it's play by the rules in the POD, i suppose?



    perl -e '$,=$",$_=(split/\W/,$^X)[y[eval]]]+--$_],print+just,another,split,hack'er

      that the module has been around for almost a decade now, I'm not convinced the behaviour is due to an oversight.

      Contrary to what's been said, undef is not the same as zero, so fixing it would break backwards compatibility. The greater the length of time since it has been decided, the harder it is to fix. It doesn't lessen the chance of it being an oversight.

      A reply falls below the community's threshold of quality. You may see it by logging in.