in reply to List context, expression precedence, and ()
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")
|
|---|