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.


In reply to Re^4: List::Util::sum() and empty lists... by blazar
in thread List::Util::sum() and empty lists... by blazar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.