in reply to Re^7: shift on empty array in list context broken (show context)
in thread shift on empty array in list context broken

see Update

Ok I've had another go. This time within the debugger and the output is leaning more towards concise. However, I am now unsure whether I have something that could relate to the issue or if it's because am still noobing DB.

Apart from getting contexts out of kilter, there are a couple of issues. Firstly,( moved to new SoPW Should high traceDepth trace into debugger code? )

Secondly, I get a 'panic' warning, about attempting to copy a freed scalar. So I'm in panic mode and posting this now, along with the trace I attempted. Its probably nothing right?

DB<57> x sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ +shift @d }; ${ wants( @a ) } 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; ${ wants( @a ) }; 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; ${ wants( @a ) }; in $=main::wants() from (eval 50)[C:/Dwimperl/perl/lib/perl5db.pl:640 +]:2 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; ${ wants( @a ) }; 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; ${ wants( @a ) }; 0 undef DB<58> x sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ sh +ift @d }; ${ wants( undef @b ) } 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; ${ wants( undef @b ) }; 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; ${ wants( undef @b ) }; in $=main::wants(undef) from (eval 51)[C:/Dwimperl/perl/lib/perl5db.p +l:640]:2 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; ${ wants( undef @b ) }; 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; ${ wants( undef @b ) }; 0 undef DB<59> x sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ sh +ift @d }; @{ wants( @c , undef @c ) } 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; @{ wants( @c , undef @c ) }; 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; @{ wants( @c , undef @c ) }; in $=main::wants('', 1, undef, 2, undef) from (eval 52)[C:/Dwimperl/p +erl/lib/perl5db.pl:640]:2 2: sub wants{ @d = @_; wantarray ? ( shift @d, shift @d ) : \ s +hift @d }; @{ wants( @c , undef @c ) }; panic: attempt to copy freed scalar 302528c to 30257dc at (eval 52)[C: +/Dwimperl/perl/lib/perl5db.pl:640] line 2.

Update Ok scratch that, I added use strict; Also, moved the 'Firstly' out to a new SoPW.

DB<69> x use strict; my @d; my @a; sub wants{ @d = @_; wantarray ? ( s +hift @d, shift @d ) : shift @d }; wants( @a ) in $=CODE(0x3025d1c)() from (eval 62)[C:/Dwimperl/perl/lib/perl5db.pl +:640]:2 in $=strict::import('strict') from (eval 62)[C:/Dwimperl/perl/lib/pe +rl5db.pl:640]:2 2: use strict; my @d; my @a; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @a ); 2: use strict; my @d; my @a; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @a ); 2: use strict; my @d; my @a; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @a ); in @=main::wants() from (eval 62)[C:/Dwimperl/perl/lib/perl5db.pl:640 +]:2 2: use strict; my @d; my @a; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @a ); 2: use strict; my @d; my @a; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @a ); 0 undef 1 undef DB<70> x use strict; my @d; my @b; sub wants{ @d = @_; wantarray ? ( s +hift @d, shift @d ) : shift @d }; wants( undef @b ) in $=CODE(0x3025f1c)() from (eval 63)[C:/Dwimperl/perl/lib/perl5db.pl +:640]:2 in $=strict::import('strict') from (eval 63)[C:/Dwimperl/perl/lib/pe +rl5db.pl:640]:2 2: use strict; my @d; my @b; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( undef @b ); 2: use strict; my @d; my @b; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( undef @b ); 2: use strict; my @d; my @b; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( undef @b ); in @=main::wants(undef) from (eval 63)[C:/Dwimperl/perl/lib/perl5db.p +l:640]:2 2: use strict; my @d; my @b; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( undef @b ); 2: use strict; my @d; my @b; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( undef @b ); 0 undef 1 undef DB<71> x use strict; my @d; my @c; sub wants{ @d = @_; wantarray ? ( s +hift @d, shift @d ) : shift @d }; wants( @c, undef @c ) in $=CODE(0x30280a4)() from (eval 64)[C:/Dwimperl/perl/lib/perl5db.pl +:640]:2 in $=strict::import('strict') from (eval 64)[C:/Dwimperl/perl/lib/pe +rl5db.pl:640]:2 2: use strict; my @d; my @c; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @c, undef @c ); 2: use strict; my @d; my @c; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @c, undef @c ); 2: use strict; my @d; my @c; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @c, undef @c ); in @=main::wants(undef) from (eval 64)[C:/Dwimperl/perl/lib/perl5db.p +l:640]:2 2: use strict; my @d; my @c; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @c, undef @c ); 2: use strict; my @d; my @c; sub wants{ @d = @_; wantarray ? ( +shift @d, shift @d ) : shift @d }; wants( @c, undef @c ); 0 undef 1 undef DB<72>

After attempting to do as you suggested, and reading plenty (read not nearly enough) of documentation, I have a little more appreciation for the debugger and how it can be used. If not actually managing to get any closer to the OP.

As for using wantarray to view the contexts, for a moment there I thought there was a void built-in.

But I see now that they are word-strings being returned to represent contexts.

documentation visited

Replies are listed 'Best First'.
Re^9: shift on empty array in list context broken (show context)
by LanX (Saint) on Jul 20, 2019 at 19:31 UTC
    Sorry, but what are you trying to show here?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      hello LanX

      Apparantley I am trying to show how little I understand contexts, module building and the debugger. :laugh

      I think what I am trying to get at is in principle what the OP is about. A reason for equivalent built-ins providing alternate implementations.

      Framing the issue of assignment in differing contexts by different built-ins within a wider context, so to speak.

      Amalgamating my existing Perl knowledge along with recently learnt knowledge, to do so. With varying results in the offspring.

      As an example, if this is an issue with shift, does pop return a different result?

      Also I am looking at how the comma operator is affecting the return list. I am not clear on which built-in is returning undef or empty in list context

        > Apparantley I am trying to show how little I understand contexts,

        In that case you might be interested in playing with B::Deparse .

        The -p option will highlight precedence, which is crucial for context

        $ perl -MO=Deparse,-p $a, $b = 666 ($a, ($b = 666)); - syntax OK $

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice