From 9f204b19b027564fb3580e124c2b4d15111abd9c Mon Sep 17 00:00:00 2001 From: Patrick Abi Salloum Date: Thu, 9 Sep 2010 23:07:24 +0300 Subject: [PATCH] 1..* ... 5 and @fib ... 8 (where @fib is infinite lazy) now work --- src/core/operators.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/operators.pm b/src/core/operators.pm index 115c1a906cf..0cc64990388 100644 --- a/src/core/operators.pm +++ b/src/core/operators.pm @@ -374,16 +374,16 @@ our sub _HELPER_generate-series(@lhs, $rhs , :$exclude-limit) { } my sub infinite-series (@lhs, $limit ) { - my $next = get-next-closure(@lhs , $limit ); - gather { - for 0..^(@lhs.elems - 1) -> $i { take @lhs[$i]; } - take @lhs[*-1] unless @lhs[*-1] ~~ Code; + my $i = 0; + while @lhs[$i+1].defined { take @lhs[$i]; $i++; } #We blindly take all elems of the LHS except last one. + take @lhs[$i] unless @lhs[$i] ~~ Code; #We don't take the last element if it is code because it will be used as $next closure + my $next = get-next-closure(@lhs , $limit ); my $arity = $next.count; - my @args=@lhs; + my @args=@lhs; #TODO: maybe avoid copying the whole array into args pop @args if @args[*-1] ~~ Code; - @args.munch( @args.elems - $arity ); #We make sure there are $arity elems + @args.munch( @args.elems - $arity ); #We make sure there are $arity elems in args loop { #Then we extrapolate using $next and the $args my $current = $next.(|@args) // last;