Since even that list doesn't return a list, would it be accurate to say "a list can't be returned in scalar context"

Sorry for the delay in getting back to you, but this was one of those things that I had to allow to wash over me for a while before deciding how to respond.

If for no other reason than you believe it is more accurate, then I would have to conclude that it probably is more accurate. And as a generality, most of what you say is accurate. That's (for me) a given.

But the real question is: whom does that greater accuracy benefit?

I thik we can agree, this (1,2,3) is a list; and this return (1,2,3) a return statement; and this

sub x{ return(1,2,3); }

is a function (attempting) to return a list.

If we place a call to that function in a scalar context my $x = x(); then the return statement doesn't cease to be a return statement, nor does the list cease to be a list. At some point, the list is transformed to a scalar, which, in this case, happens to be the last element of the list.

So at that point, immediately before the transformation--and the very reason the transformation is performed--the list is in a scalar context.

Now you could conclude either of:

But whichever way, and to be honest it does matter which is more accurate, the list existed; the scalar context existed and the list was within the auspices of that scalar context; and so, was transformed.

So, I see no clearer, simpler or conceptually more accurate way of describing that than: "the results of a list in a scalar context is the last element of that list".

And this does not apply to map & grep in scalar contexts, not because the description or concept is wrong, but because those functions do not attempt to return a list when they find themselves in a scalar context. They instead choose to return something, a scalar, that is considered more useful.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^11: Scalar context of slice ("list") by BrowserUk
in thread Scalar context of slice by thenaz

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.