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

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.

Replies are listed 'Best First'.
Re^13: Scalar context of slice ("list")
by BrowserUk (Patriarch) on Oct 20, 2008 at 04:57 UTC

    Okay. If accuracy is so important, then I guess I should wish you luck in balancing yourself upon your buttocks and thighs, with your torso more or less upright, atop your above-average statured, domesticated, odd-toed, solid-hoofed, herbivorous, ungulate quadruped mammal.


    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.

      It's my understanding that you're the one who complained about the inaccuracy (Re^5: Scalar context of slice (myth)) and thus the ensuing pursuit.

      What I don't understand is how "a list can't be returned in scalar context" compares to "balancing yourself upon your buttocks and thighs, with your torso more or less upright, atop your above-average statured, domesticated, odd-toed, solid-hoofed, herbivorous, ungulate quadruped mammal".

      It's my understanding that you're the one who complained about the inaccuracy (Re^5: Scalar context of slice (myth)) and thus the ensuing pursuit.

      What I don't understand is how "a list can't be returned in scalar context" compares to "balancing yourself upon your buttocks and thighs, with your torso more or less upright, atop your above-average statured, domesticated, odd-toed, solid-hoofed, herbivorous, ungulate quadruped mammal".