Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by mr_mischief (Monsignor)
on Oct 29, 2008 at 22:52 UTC ( #720355=note: print w/ replies, xml ) Need Help??


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

Taking into account operator precedence in your first example, the 1 is all that's in scalar context. There is nothing to present a list to the assignment operator at all, and each element item to the right of the assignment operator gets its context separately (two thirds of them getting void context).

Likewise taking into account operator precedence in your second example, only @y is in scalar context. The exception that an array in scalar context yields its length is in effect, and that's what $x gets assigned.

No lists are presented to the operators due to comma being lower in precedence than assignment. I don't see how one's thinking about lists even becomes involved with the thinking about the assignment unless someone doesn't know that the comma operator is lower precedence than assignment.

If someone doesn't understand operator precedence, they have bigger issues than just a mental model of lists.

BTW, I've never programmed more than a couple of dozen lines of Python, total. I also think candy-flavored unicorns sound delightful, if a bit dangerous to taste.

Now, if we were dealing with a concept of lazy vs. eager assignment operators or specific atom and list assignment operators (which would need different names and not both be simply '=') instead of context being determined by the left operand of the infix operator, then that'd be another story. That'd be a different language, too, though.


Comment on Re^5: If you believe in Lists in Scalar Context, Clap your Hands
Select or Download Code
Re^6: If you believe in Lists in Scalar Context, Clap your Hands
by chromatic (Archbishop) on Oct 30, 2008 at 07:14 UTC
    If someone doesn't understand operator precedence, they have bigger issues than just a mental model of lists.

    Yes. I agree. Every novice I've seen confused by the idea of "a list in scalar context" has had tremendous trouble understanding operator precedence and exactly what makes up a list in Perl. Context and operator precedence are the problem, not listishness.

      Sometimes the illusion is more useful than reality.

      If you doubt this, consider all the useful 3D representations you use daily, drawn on 2D surfaces...whether they be games or icons or "3D bar charts" drawn on computer screens; or photos or painting around your home or office; exploded views in assembly manuals; signposts and diagrams of all kinds.

      Further, 'inaccurate conceptual models' can serve both the beginner and the expert alike.

      If you covered any electrical or electronics in your education, you probably started off thinking that "electricity flows from positive to negative". And then got pissed with your previous instructors when they queered the pot by telling that electrons actually flow from negative to positive. And then queered it further by telling you that most of the equations you would need for real world electrical and electronic engineering would require you to continue signing your electrical quantities as if the former was true; due to convention.

      Getting hung up on reality has probably been the downfall of more students come exam time than inability.


      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-09-19 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (132 votes), past polls