Aaron Sherman wrote: > > > $ref = [1,2]; > > > @ary[$ref] = foo(); # probably a syntax error > > Ok, as far as I can recall, Larry hinted that arrays and references to > arrays would be interchangable in many contexts in P6. In this case, I > can't see any reason that subscripting would *want* to do a SvIV on > a known reference, so I would expect it to obey that logic and treat > the reference as an array. Thus, I expect this to be list context for > the exact same reason that: > > @bar = (1,2); > @ary[@bar] = foo(); > > would be.
The problem is *when* perl determines the context. If it's at compile-time, then you can't say what $ref contains, so you can't conclude anything except that it will be a scalar value (hence scalar context). Checking it at run-time will give you the array/ref duality, but there's likely to be a *major* performance hit if every use of a variable subscript has to be run-time checked for context. Hence, I suspect the rule will be something like: if it's identifiably an array, list, or array ref at compile-time, it's a slice (and hence list context); otherwise, it's a single element. After all, it's not such a terrible burden to have to write the above as: @ary[@$ref] = foo(); is it? Of course, if one were to write: my $ref is const = [1,2]; or: my ARRAY $ref = [1,2]; then $ref *is* compile-time identifiable as an array ref, so you get a slice, which confers list context. That's kinda icky. > Next question, though: > > $val = (foo())[0]; > > List? That would be my expectation. Just as in Perl 5. Damian