in reply to [Perl 6] single-value vs. array slices

An array subscript will, by default, be evaluated in slice context.

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
    TimToady stopped by the CB while this thread was being discussed, and said that by default the brackets always work in list context. He and some others pointed to S02:1377 as the documentation. I've not been keeping very current lately on Perl6, but I hope the link helps.
      Yes, that very section in the documentation was updated already this month based on problems I found. The example was showing context changes in "other places", that is clearly against the rules now.

      —John