Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: If you believe in Lists in Scalar Context, Clap your Hands

by JavaFan (Canon)
on Oct 23, 2008 at 21:55 UTC ( #719175=note: print w/ replies, xml ) Need Help??


in reply to Re^2: If you believe in Lists in Scalar Context, Clap your Hands
in thread If you believe in Lists in Scalar Context, Clap your Hands

I didn't know Perl read the manual page.

As I said, "List" is a concept for humans. The fact that LIST is mentioned in the manual page only supports that notion - after all, it's humans who read the manual page.

For Perl, map just has a sequence of scalars as arguments.


Comment on Re^3: If you believe in Lists in Scalar Context, Clap your Hands
Re^4: If you believe in Lists in Scalar Context, Clap your Hands
by tilly (Archbishop) on Oct 23, 2008 at 22:26 UTC
    By your reasoning, the fact that strings are mentioned in the manual page supports the notion that strings are only a concept for humans, but are not really part of the Perl language.

    Are you truly unable to see the problem with this line of reasoning?

      By your reasoning, the fact that strings are mentioned in the manual page supports the notion that strings are only a concept for humans, but are not really part of the Perl language.
      Right.

      Suppose I had claimed that birds are black. And oshalla disagrees, and shows pictures of ravens. Now, that wouldn't support his case, would it?

      If I say that lists are a concept for humans, and someone shows the manual page - which is intended for humans - mentioning lists, than it only supports my claim. It doesn't follow that my claim is true - but it certainly doesn't disprove it.

Re^4: If you believe in Lists in Scalar Context, Clap your Hands
by moritz (Cardinal) on Oct 23, 2008 at 22:43 UTC
    Sorry, I think you're just acting stupid right now.

    perlfaq4 even has the question What is the difference between a list and an array?, and the answer isn't "there is no list in Perl".

    For the user of a programming language the internals of the interpreter are irrelevant, and if the documentation uses a notion all over the place, you'd do very well to accept that this thing actually exists.

    Calling things "sequence of scalars" instead of "list" doesn't make things clearer or more precise.

Re^4: If you believe in Lists in Scalar Context, Clap your Hands
by oshalla (Deacon) on Oct 23, 2008 at 23:09 UTC

    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:

    1. the length of the list that would have been returned in List Context.
    2. the last item of the list that would have been 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.

Re^4: If you believe in Lists in Scalar Context, Clap your Hands
by ysth (Canon) on Oct 28, 2008 at 05:01 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://719175]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (16)
As of 2014-10-20 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (85 votes), past polls