Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Yes. I'd say that an array is a variable whose value is a list. Using the name or some other reference to an array yields that value or its length, depending on Context. In that sense, yes, I was implying that arrays do not make lists. A slice operation, on the other hand, takes a list value and makes a list which is a subset. (I'm open minded, though: if there is, in fact and invisible operator that makes lists out of arrays I would not be surprised.)
No.
An array returns a list in list context, but it isn't a list. Just as localtime() isn't a list, although it will return a list in list context. In fact, every expression will return a list in list context, although that list may be empty or just contain a single value.

A flat "No". Goodness.

I'm puzzled by what you are contradicting here. Is it controversial to say that an array is a variable ? Is it then controversial to say the the value of that variable is a list ? Or to note that in an expression, the part of the value used (the list itself or its length) depends on the Context, is that controversial ?

As for the slice operation, yes, it will take a subset of a list. On arrays though, it can return more.
@a = ()[3, 5, 6]; @b = @c[3, 5, 6]; say 0 + @a; say 0 + @b; __END__ 0 3

Well, that's amusing. I note that it doesn't matter whether @c is undefined or defined but empty. So, slices of lists are different from slices of arrays. Splendid. Thank you.

(I realise also that subset might be the wrong word, since a slice can also include repeated values, which might not pass as a subset. Also, as you point out, some items in the slice may be undef, which may or may not be considered as part of the original.)

You are quite wrong here. The list assignment operator in scalar context DOES NOT RETURN A LIST. It returns the number of elements on its right hand side. It sets $a and $b as side-effects - it doesn't return its left hand side.

SO IT WOULD APPEAR.

I was trying to say: to fully understand $r = ($a, $b) = 0..11;   it is necessary to know what a many-splendored thing '=' is. Understanding the more common-place notion of right-associativity is not enough. I'm sorry if that wasn't as clear as I had hoped.

I do not know how this is actually implemented. I can see how the documentation describes it. The effect remains as if the scalar assignment reaches round the list assignment, but I am more than happy to take your word for it that it doesn't actually work like that.

Further, I withdraw unreservedly any implication, imputation or suggestion that this (or any other) mechanism in Perl might, through a glass darkly, or otherwise, appear to be magical to even the slightest degree. I throw myself on the mercy of the court, and hope, as only a true penitent can hope, for a light sentence involving the minimum of pain, and if at all possible, no permanent disfigurement.


In reply to Re^6: If you believe in Lists in Scalar Context, Clap your Hands by oshalla
in thread If you believe in Lists in Scalar Context, Clap your Hands by oshalla

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (10)
    As of 2014-12-18 18:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (59 votes), past polls