Re: Apropos of nothing...
On Sun, Dec 16, 2001 at 03:55:10PM +1100, Damian Conway wrote: [...] And, just for laughs: $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. Next question, though: $val = (foo())[0]; List? -- Aaron Sherman [EMAIL PROTECTED] finger [EMAIL PROTECTED] for GPG info. Fingerprint: www.ajs.com/~ajs6DC1 F67A B9FB 2FBA D04C 619E FC35 5713 2676 CEAF Write your letters in the sand for the day I'll take your hand In the land that our grandchildren knew. -Queen/_'39_
Re: Apropos of nothing...
Aaron Sherman [EMAIL PROTECTED] writes: On Sun, Dec 16, 2001 at 03:55:10PM +1100, Damian Conway wrote: [...] And, just for laughs: $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. Next question, though: $val = (foo())[0]; List? Scalar, obviously. With a possible runtime error if foo doesn't return an arrayref. And that should probably written as: $val = foo().[0] -- Piers It is a truth universally acknowledged that a language in possession of a rich syntax must be in need of a rewrite. -- Jane Austen?
Re: Apropos of nothing...
$val = (foo())[0]; List? Scalar, obviously. How do you figure that? (Not a criticism: I'd really like to understand your thought process here so I can assess the relative DWIMity of the two alternatives). With a possible runtime error if foo doesn't return an arrayref. And that should probably written as: $val = foo().[0] Or even: $val = foo.[0]; Or even: $val = foo[0]; Note that, in these last three versions, foo() is indeed called in a scalar context, specifically a scalar array ref context. (!) Damian
Re: Apropos of nothing...
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
Re: Apropos of nothing...
Damian Conway [EMAIL PROTECTED] writes: $val = (foo())[0]; List? Scalar, obviously. How do you figure that? (Not a criticism: I'd really like to understand your thought process here so I can assess the relative DWIMity of the two alternatives). I figure I'm going mad actually. Misread the initial post. (foo())[0] is distinct from (foo()).[0], or foo[0] or all the other options. -- Piers It is a truth universally acknowledged that a language in possession of a rich syntax must be in need of a rewrite. -- Jane Austen?