Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't tail a tail. #6646

Closed
p6rt opened this issue Dec 7, 2017 · 4 comments
Closed

Can't tail a tail. #6646

p6rt opened this issue Dec 7, 2017 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Dec 7, 2017

Migrated from rt.perl.org#132543 (status was 'resolved')

Searchable as RT132543$

@p6rt
Copy link
Author

p6rt commented Dec 7, 2017

From @briandfoy

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.

@p6rt
Copy link
Author

p6rt commented Dec 8, 2017

From @zoffixznet

On Thu, 07 Dec 2017 15​:48​:35 -0800, comdog wrote​:

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​: rakudo/rakudo@af9812fa73
Tests​: Raku/roast@88a12f6984f0b57e9
  Raku/roast@1743894c03

@p6rt
Copy link
Author

p6rt commented Dec 8, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 8, 2017

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant