Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bring back List.rotor
Fixes hang in t/spec/S32-list/rotor.t
  • Loading branch information
niner committed Aug 16, 2015
1 parent 6fa6bef commit de6156a
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions src/core/List.pm
Expand Up @@ -665,39 +665,40 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
}

# XXX GLR
#method rotor(List:D: *@cycle, :$partial) is nodal {
# die "Must specify *how* to rotor a List"
# unless @cycle.infinite || @cycle;
#
# my $finished = 0;
# # (Note, the xx should be harmless if the cycle is already infinite by accident.)
# my @c := @cycle.infinite ?? @cycle !! @cycle xx *;
# gather for @c -> $s {
# my $elems;
# my $gap;
# if $s ~~ Pair {
# $elems = +$s.key;
# $gap = +$s.value;
# }
# elsif $s < 1 {
# die "Cannot have elems < 1, did you mean to specify a Pair with => $s?";
# }
# else {
# $elems = +$s;
# $gap = 0;
# }
#
# if $finished + $elems <= self.gimme($finished + $elems) {
# take self[$finished ..^ $finished + $elems];
# $finished += $elems + $gap;
# }
# else {
# take self[$finished .. *]
# if $partial and $finished < self.elems;
# last;
# }
# }
#}
method rotor(List:D: *@cycle, :$partial) is nodal {
die "Must specify *how* to rotor a List"
unless @cycle.is-lazy || @cycle;

my $finished = 0;
# (Note, the xx should be harmless if the cycle is already infinite by accident.)
my @c := @cycle.is-lazy ?? @cycle !! (@cycle xx *).list;
gather for flat @c -> $s {
my $elems;
my $gap;
if $s ~~ Pair {
$elems = +$s.key;
$gap = +$s.value;
}
elsif $s < 1 {
die "Cannot have elems < 1, did you mean to specify a Pair with => $s?";
}
else {
$elems = +$s;
$gap = 0;
}

$!todo.reify-at-least($finished + $elems) if $!todo.DEFINITE;
if $finished + $elems <= nqp::elems($!reified) {
take self[$finished ..^ $finished + $elems];
$finished += $elems + $gap;
}
else {
take self[$finished .. *]
if $partial and $finished < self.elems;
last;
}
}
}

proto method combinations($?) is nodal {*}
multi method combinations( Int $of ) {
Expand Down

0 comments on commit de6156a

Please sign in to comment.