in reply to [Perl 6] single-value vs. array slices
Note that Perl 6 signature allow multi method dispatch that distinguishes between these two cases;
my @a = 1; my_sub(@a, 2); # and my_sub(1, 2);
This is possible because lists don't flatten in slice context. (Slice context is something like multi-dimensional list context).
So I know that @a[1] returns a single scalar value, the one that is stored in @a. @a[@other_list_with_many_values] will always produce a list, which is transformed to a capture (think reference here) in generic item context, and to the number of elements in numeric context.
I don't know what @a[@list_with_one_element] returns, but it seems logical that it returns a list as well. If you want it to return a single element, not a list, you can flatten the array:
@a[|@list_with_one_element];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [Perl 6] single-value vs. array slices
by mr_mischief (Monsignor) on Mar 31, 2008 at 16:18 UTC | |
by John M. Dlugosz (Monsignor) on Mar 31, 2008 at 19:14 UTC |