Okay, that now makes sense.

What actually helped shed light on it was using your ctx function in this code:

sub ctx { my $w = wantarray; print "$_[0]:"; print ( defined $w ? ($w?'array':'scalar') : 'void'); print "\n"; \&ctx; } sub ctxind { my $w = wantarray; print "$_[0]:"; print ( defined $w ? ($w?'array':'scalar') : 'void'); print "\n"; 1; } my $a = [ ctx("buildA1"),ctx("buildA2"),ctx("buildA3"),ctx("buildA4") +]; ctx("by itself"); @{$a}[ctxind("slice ndx")]; $a -> [ctxind("plain ndx")] -> ("fn1",ctx("args1"),ctx("args2")) -> ("fn2",ctx("args3"));
This yields:
buildA1:array buildA2:array buildA3:array buildA4:array by itself:void slice ndx:array args3:array args1:array args2:array plain ndx:scalar fn1:scalar fn2:void

Which now all makes sense, except for the "args3" being evaluated before "args1". That seems like a rather bizarre evaluation order.

The contexts inside () on the function references are all array context, and the context inside [] is array or scalar depending only on the immediately surrounding syntax. The context of the function called by the dereference itself depends on the surrounding code.

I guess if TIEARRAY worked better, I'd be able to tie the array that $a points to and see that the FETCH method was getting called with different contexts depending on the code surrounding the array ref, even though the context applied to the expression generating the index was determined only by wheter I'd used the slice syntax or not. Unfortunately, it appears that FETCH is always called in scalar context, no matter what.

--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

In reply to Re^6: Is this a bug, or expected behavior? by fizbin
in thread Is this a bug, or expected behavior? by fizbin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.