Why can't I tail
the result of a tail
? I can call head
on the sequence tail
returns (and other variations), but a tail
on a tail
doesn't work (in 2017.10):
> my $list = <a b c d e f g h i j>;
(a b c d e f g h i j)
> $list.head(5).head
a
> $list.head(5).tail
e
> $list.tail(5).head
f
This one fails:
> $list.tail(5).tail
Nil
But throwing a list
in there works:
> $list.tail(5).list.tail
j
tail
returns aSeq
type andSeq
does not have atail
method on it, you must first convert it to a list (either with.list
or.List
) before you can call the subsequenttail
method on it. But it doesn't make sense why it works forhead
... – Gringo$list.tail(5).tail(1)
and it works, but just not with$list.tail(5).tail
. Why does the default parameter not work in the second case? – Gringo.tail
and.tail(1)
are implemented withRakudo::Iterator.LastValue
andRakudo::Iterator.LastNValues
respectively, which differ quite a bit in implementation. github.com/rakudo/rakudo/blob/master/src/core/Rakudo/… - here's the problematic one. – ArmitageList
takes an iterator and skips it ahead$n
items. then, the tail method onSeq
callscount-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 forcount-only
, or it should calculate the proper amount of items left. – Armitage