Skip Menu |
Report information
Id: 132543
Status: resolved
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: comdog <brian.d.foy [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: rakudobug [...] perl.org
Date: Thu, 7 Dec 2017 18:47:47 -0500
From: brian d foy <brian.d.foy [...] gmail.com>
Subject: Can't tail a tail.
I first asked about this on Stackoverflow: https://stackoverflow.com/q/47704428/2766176 A .tail on a .tail appears to do the wrong thing: Show quoted text
> my $list = <a b c d e f g h i j>;
(a b c d e f g h i j) Show quoted text
> $list.tail(5).tail
Nil But throwing a list in there works: Show quoted text
> $list.tail(5).list.tail
j Timo said: .tail and .tail(1) are implemented with Rakudo::Iterator.LastValue and Rakudo::Iterator.LastNValues respectively, which differ quite a bit in implementation. https://github.com/rakudo/rakudo/blob/master/src/core/Rakudo/Iterator.pm#L1807 And he figures: tail on the List takes an iterator and skips it ahead $n items. then, the tail method on Seq calls count-only on it to figure out how far to skip ahead to get the last $m items. However, count-only on the first iterator just gives you the total number of items in the original list. It should probably either signal an error when asked for count-only, or it should calculate the proper amount of items left.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.2k
On Thu, 07 Dec 2017 15:48:35 -0800, comdog wrote: Show quoted text
> I first asked about this on Stackoverflow: > > https://stackoverflow.com/q/47704428/2766176 > > A .tail on a .tail appears to do the wrong thing: >
> > my $list = <a b c d e f g h i j>;
> (a b c d e f g h i j) >
> > $list.tail(5).tail
> Nil > > But throwing a list in there works: >
> > $list.tail(5).list.tail
> j > > Timo said: > > .tail and .tail(1) are implemented with > Rakudo::Iterator.LastValue and > Rakudo::Iterator.LastNValues respectively, which differ > quite a bit in implementation. > https://github.com/rakudo/rakudo/blob/master/src/core/Rakudo/Iterator.pm#L1807 > > And he figures: > > tail on the List takes an iterator and skips it ahead $n > items. then, the tail method on Seq calls count-only on > it to figure out how far to skip ahead to get the last > $m items. However, count-only on the first iterator just > gives you the total number of items in the original > list. It should probably either signal an error when > asked for count-only, or it should calculate the proper > amount of items left.
Thank you for the report. This is now fixed. Fix: https://github.com/rakudo/rakudo/commit/af9812fa73 Tests: https://github.com/perl6/roast/commit/88a12f6984f0b57e9 https://github.com/perl6/roast/commit/1743894c03


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org