in reply to [Perl 6] $ and @ - what is it coming to?
In generic item context an array returns a capture (think reference) to an array.
But in other item contexts, like boolean ?@array, numeric +@array and string ~@array the array will return different things (for example number of elements, and a string representation).
A scalar value that holds an array capture automatically dereferences, so you can write $ary[0] instead of the cludgy $ary->[0].
I don't know why this should make sigils useless. Sigils serve two purposes: visual distinction, and name disambiguation (%foo is a different variable than @foo).
Automatic dereferencing doesn't impact any of those.
It's like in Perl 5 - you can store everything in a scalar (or scalar ref), but you shouldn't, because it makes your program less readable.
But if you decide to do that in Perl 6, the syntax is nicer ;-)
Update: as a side note the braces after a variable are nothing special or magical in Perl 6, it just calls method postcircumfix:<[ ]>($invocant:, $argument) on the variable. So it's just natural that it works on a capture as well as on an array.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [Perl 6] $ and @ - what is it coming to?
by amarquis (Curate) on Mar 25, 2008 at 15:47 UTC | |
|
Re^2: [Perl 6] $ and @ - what is it coming to?
by John M. Dlugosz (Monsignor) on Mar 27, 2008 at 04:26 UTC | |
by moritz (Cardinal) on Mar 31, 2008 at 08:57 UTC | |
by John M. Dlugosz (Monsignor) on Mar 31, 2008 at 09:50 UTC | |
by moritz (Cardinal) on Mar 31, 2008 at 12:36 UTC |