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

By many definitions, it is. It is a list literal. It becomes a list operator when compiled. A list is created on the stack when executed. However, it doesn't necessarily return a list.

Now you could conclude either of:

One could conclude one of those items, but they'd be wrong by doing so. All three conclusions are predicated on a list being passed to return, but that's not the case. A function's return statement never sees a list when the function is called in scalar context.

In this case, return is passed the result of a list operator. When executed in scalar context, a list operator returns a scalar.

nor does the list cease to be a list.

Saying the list ceases to be a list is interestingly correct since the list reduces itself to a scalar.

And this does not apply to map & grep in scalar contexts [...] because those functions do not attempt to return a list when they find themselves in a scalar context.

Neither does a list. We've already seen the code.

They instead choose to return something, a scalar, that is considered more useful.

So does a list.

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".

It's no clearer than the original disputed statement ("there is no such thing as a list in scalar context") for reasons that should be obvious from this thread (different understandings of what consists a list).

But as clear, simple and accurate as it might be, it's totally useless. The disputed statement is used to describe how operators and functions behave in scalar context. It can't be replaced with a statement that's specific to one operator.


In reply to Re^12: Scalar context of slice ("list") by ikegami
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.