|XP is just a number|
Re^4: If you believe in Lists in Scalar Context, Clap your Handsby gone2015 (Deacon)
|on Oct 23, 2008 at 23:09 UTC||Need Help??|
Let's suppose for a moment that Perl, as a language, is a collection of concepts, without worrying too much about how a program written using that language is executed.
It seems to me that in this language the list (or LIST) is an important element. It appears that lists may appear as arguments in expressions and may be the result of expressions.
I can see that it is possible to take the view that lists (in this abstract sense) can only exist in List Context. Trivially then there can never be a List in Scalar Context.
This view requires a Scalar Context variant for every instance of something that in List Context would return a list. The Scalar interpretation of ',' is well known. Similar definitions are required for slice operations, and for anything else that can return a list in the appropriate context.
It's true that in the limit, Perl being what it is, the programmer should never assume any particular behaviour in a Scalar Context based on knowledge of the List Context behaviour.
Bearing that in mind, there are two common Scalar Context results where a list is returned in List Context:
These are, of course, not the only results -- just common ones.
As common as they are, my feeling is that these behaviours could usefully be given a name. Then using that name the programmer might reduce the intellectual load by categorising some things as Type-1 list operations and others as Type-2.
It would be nice to have a more memorable or meaningful names for these... perhaps something that relates to concepts already understood ?
I have a couple of fairly obvious suggestions. But perhaps I have uttered enough heresy for today.