http://www.perlmonks.org?node_id=1090209


in reply to Re^4: There's scalar(), but no list(). Perl could need one for rare but reasonable use
in thread There's scalar(), but no list(). Perl could need one for rare but reasonable use

You are saying simply "list" to refer to what is more precisely referred to as a "list literal" (parens around a bunch of expressions separated by comma operators). This is quite often done, but you have to pay attention to the (English) context of the text to discern when. There are other places where simply "list" is used to refer to a "list of scalar values", a more general concept rather than a syntactical construct.

It is easy to get confused when reading multiple sources, some of which are saying "list" to mean "list literal" and some saying "list" to mean "list of scalar values". This is especially true because lots of the things don't conflict between those two concepts.

For example, calling a sub in "list context" certainly does not mean that the context of the call is part of a list literal. And an array stores a list of scalar values (that may have come from a list literal or not).

You seem to be struggling with trying to force features of list literals onto other types of Perl lists.

lists do not form a data type at all. Lists are a purely syntactic concept,

A list (of scalar values) is certainly a type of data in Perl. It isn't a "data type" to the point of being a type of variable (nor a type of reference). But a "list slice" can be performed on any list (of scalar values). A list is a common but ephemeral type of data in Perl (which is usually stored on the Perl stack).

When documentation talks about a 'sub' that "returns a list", it doesn't mean a 'sub' that has the 'return' keyword followed by a list literal. It means that calling the subroutine results in 0 or more scalar values being pushed onto the Perl stack and those being available at the point where the 'sub' was called. That is the type of data that the 'sub' returns to the caller. But that also only happens if the 'sub' was called from a list context.

See also Re^3: wantarray alternative (choice) and the rest of that thread.

- tye        

  • Comment on Re^5: There's scalar(), but no list(). Perl could need one for rare but reasonable use ("list")

Replies are listed 'Best First'.
Re^6: There's scalar(), but no list(). Perl could need one for rare but reasonable use ("list")
by LanX (Saint) on Jun 17, 2014 at 22:11 UTC
    Thanks a lot for this approach to get the terminology right and to distinguish between "literal list" (notation) and "list assign" ( like returning multiple values on the stack).

    Would help a lot if we could clean up terminology.

    Cheers Rolf

    (addicted to the Perl Programming Language)

Re^6: There's scalar(), but no list(). Perl could need one for rare but reasonable use ("list")
by flowdy (Scribe) on Jun 18, 2014 at 19:40 UTC

    Thanks too, I see definitely clarity ahead. The last mile to understanding lists and why there is no dedicated operator to impose list context I will go on my own, since I do not want to suggest newbies, by defending and provoking confusion, more weirdness in the internals of my beloved Perl than there probably is. When I feel the need to impose list context explicitly, I'll consider first wantarray and take one of the expressions in the thread and add a comment on why.

    Thanks a lot for your time and wisdom,
    -- flowdy