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

We don't have to quibble over semantics, do we??

Not really. Mathematically, there's no common notion of "undefined list". But that may well be a whole another story. OTOH there's no Perl concept of "undefined list" that I know of, either. There are "undefined values", but they bear no relevance to what we're discussing of. That an empty list may be "undefined" to you is something I can accept as a matter of respect for your opinion, but not something I can make sense of.

To me a list is undefined even if it exists but has no items to encompass

Describe a list that does not exist! Yet, whatever an empty list may be to you, it is perfectly well defined.

aor if it has no explicitly named members

Huh?!?

Perl is not matlab or mathematica nor would i wish it to be, even if i were a mathematician I'd appreciate the difference between the return values being 0 or undef, because logically the difference tells me something about the state of operations within the returning subroutine.

Well, that's something I appreciate too. But it's very natural to think in mathematical terms for me. And for a mathematical function, as opposed to a generic one, I expect a mathematically coherent behaviour.

I don't disagree with you or BrowserUk, it's a perfect solution to OP's problem. I just don't see (0, ()) as being the same argument list as (), neither does List::Util::sum() - one is clearly defined, another is not (or in your speak, one is empty, another is not).

Indeed (0) is not the same thing as (). Yet the sum over both lists should mathematically have the same value, that is, 0. If I wanted to distinguish between the two cases, in a mathematically oriented context I would do so a priori.

Replies are listed 'Best First'.
Re^5: List::Util::sum() and empty lists...
by Jenda (Abbot) on Dec 04, 2006 at 18:54 UTC

    Well matematically 0 and undef do have the same value. There's just the fact that Perl-wise the second may sometimes generate a warning. I tend to turn this warning off anyway because IMHO it just gets in the way.

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