Actually, () only very rarely denotes list context. I've been trying to figure out all of the possible ways to use () to create a list context and I have yet to come up with more than one: List assignment. (Perhaps I'm overlooking some?)

That is, taking a scalar assignment and adding parens around the left-hand side switches the right-hand side from scalar to list context. I can't come up with any other cases where parens change the context.

So the only change you'd need to require for Perl6 is a new syntax for list assignment. Since     [$a,$b]= @list; isn't already taken, that would work.

But, it is also true that you've misinterpretted the problem and made it to be much bigger than it really is. So perhaps the change isn't as necessary.

Actually, if we did make it so that (...)= no longer denoted a list assignment and so left the right-hand side in a scalar context, then we'd have new surprises because:      my( $a, $b )= ( 4, 5 ); would be interpretted as:      my $a; my $b= 5;

So I don't think you'll have much luck convincing Larry and Dominus to make that change.

But I have an idea for another change that might have a chance of getting accepted. How about an compile-time warning for:      ( $scalar )= EXPR that suggests that you either drop the parens or rewrite that as:      $scalar= ( EXPR )[0] depending on what you really meant?

Even that might be a bit of an up-hill fight as code like:     my( $arg )= shift; works just fine since shift returns a scalar. I don't know how easy it would be to generate the warning only if the right-hand side cared about its context...

        - tye (but my friends call me "Tye")

In reply to (tye)Re: List context, expression precedence, and () by tye
in thread List context, expression precedence, and () by pmas

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.