in reply to Re: shift on empty array in list context broken
in thread shift on empty array in list context broken

> It doesn't look like shift has a list context, at least according to perldoc.

well splice also says

The following equivalences hold
... shift(@a) splice(@a,0,1)

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

Replies are listed 'Best First'.
Re^3: shift on empty array in list context broken
by tybalt89 (Monsignor) on Jul 13, 2019 at 21:30 UTC

    splice lied! It's almost sort-of nearly true, but not completely true :)

      splice didnt lie

      The array is manipulated exactly like shift would manipulate it.

      The return value is exactly as documented for splice/shift.

      The equivalences chart is part but not the whole documentation.

        The statement is still false even if it's surrounded by true ones.

      > splice lied!

      I prefer orthogonal design :/

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

Re^3: shift on empty array in list context broken
by tybalt89 (Monsignor) on Jul 13, 2019 at 21:38 UTC

    On the other hand, try

    my @x = (); my $x = splice @x, 0, 1;

    What splice says is true in scalar context.

      what do you mean?

      DB<17> ($x= splice @x, 0, 1 ) and print "true" DB<18> p !! splice @x, 0, 1 DB<19>

      it's false for me.

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

        I believe that, by "What splice says is true in scalar context.", Tybalt meant "in scalar context, the documentation for splice holds true", not "in scalar context, splice returns a truthy value".
Re^3: shift on empty array in list context broken
by ikegami (Patriarch) on Jul 15, 2019 at 11:17 UTC

    That should be fixed. Feel free to use perlbug to submit a bug report. Please include a suggested fix.

      Reported without a precise suggestion to fix.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^3: shift on empty array in list context broken
by Don Coyote (Hermit) on Jul 21, 2019 at 14:08 UTC
    >well splice also says
    > The following equivalences hold
    > ...
    > shift(@a)     splice(@a,0,1)

    It would appear shift is doing something like this:

    DB<232> x $x=4; while( ($y)= ( $u = splice( @t,0,1 ))){ last unless +$x--; print ":$_: " } :: :: :: :: empty array

    which would make the equivalence:

    shift(@a) === ( $t = splice( @a,0,1 ) )