thanx, actually I knew this once ... : (
But in my example they do no harm, just emphasizing the right-to-left priority auf the evaluation. My explanation anyway was wrong!
Anyway: I'm a great fan of the syntactical cleansing in Perl 6 and longing to use it ASAP, with or without parrot!
UPDATE: You know, sometimes Perl-syntax is like "fizzbin" - the card game Kirk invents on the Mob planet
| [reply] |
> Except when empty, parens never do more than control precedence. Except when empty, they never create a list context.
And what about ($a)=@_; ???
Unfortunately, it's not that easy!
PS: Just Another example of perl-Fizzbin! ; )
| [reply] [d/l] |
I'm sure I read somewhere that this form can be best understood in terms of the implied or transparent comma -- from memory, that would be a Unicode "ZERO WIDTH NO-BREAK COMMA". (Known to some as the fairy or pixie comma, spreading a little List Context magic while remaining tantalizingly just out of sight. I believe that in Ireland this is also known as one of the extensive family of O'Mission leprechauns.)
| [reply] |
To correct myself, there are very special situations where parens affect the result. eof vs eof() and (...)x... vs ...x..., for example. And of course ($x)=... vs $x=....
But while parens sometimes do more than control precedence, I can't think of anywhere where non-empty parens create a list context.
The parens in ($a)=@_ don't affect context. They cause a list assignment operator (aassign) to be used instead of a scalar assignment operator (sassign).
That said, it's very convenient to think that some parens create a list, even when it isn't technically true. But the code being discussed definitely does not contain parens which could be thought of as "list forming".
| [reply] [d/l] [select] |
I've just been tripped up by:
my @foo = (2, 3, 4 x 17, 3, 2, 0, 0)
being quite different from:
my @foo = (2, 3, (4) x 17, 3, 2, 0, 0)
which looks as if the '()' confer some quality of list-ness. The documentation says:
.... In scalar context or if the left operand is not enclosed in parentheses, it returns a string consisting of the left operand repeated the number of times specified by the right operand. In list context, if the left operand is enclosed in parentheses or is a list formed by qw/STRING/, it repeats the list.
so the brackets are part of the syntax... I confess that I was (for reasons unknown) expecting 'x' to do listy things in List Context and scalary things otherwise. (Many things take lists of arguments, so I guess it would be inconvenient for (e.g.) '-' x 24 to yield a list in List Context.)
Similarly, of course, foreach VAR(LIST) BLOCK reenforces the feeling that '()' have something to do with the making of lists.
| [reply] [d/l] [select] |
DB<54> $a= join ",",(1..5)
DB<55> p $a
1,2,3,4,5
DB<56> print scalar split /,/,$a
5
DB<57> ($A)=split /,/,$a
DB<58> print $A
1
split is executed in listcontext!
| [reply] [d/l] |