Skip to content

Commit

Permalink
Change infix:<...> code to use the last three elements passed on the …
Browse files Browse the repository at this point in the history
…left-hand side to determine the series, rather than the first three.
  • Loading branch information
colomon committed May 3, 2010
1 parent c9d9a99 commit 1eef087
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/core/operators.pm
Expand Up @@ -402,6 +402,7 @@ our multi sub infix:<...>(@lhs is copy, $rhs) {
$next = @lhs.pop;
} else {
given @lhs.elems {
when 0 { fail "Need something on the LHS"; }
when 1 {
if @lhs[0] cmp $rhs == 1 {
$next = { .prec };
Expand All @@ -412,16 +413,15 @@ our multi sub infix:<...>(@lhs is copy, $rhs) {
when 2 {
$next = { $_ + (@lhs[1] - @lhs[0]) };
}
when 3 {
if @lhs[1] - @lhs[0] == @lhs[2] - @lhs[1] {
$next = { $_ + (@lhs[1] - @lhs[0]) };
} elsif @lhs[1] / @lhs[0] == @lhs[2] / @lhs[1] {
$next = { $_ * (@lhs[1] / @lhs[0]) };
default {
if @lhs[*-2] - @lhs[*-3] == @lhs[*-1] - @lhs[*-2] {
$next = { $_ + (@lhs[*-2] - @lhs[*-3]) };
} elsif @lhs[*-2] / @lhs[*-3] == @lhs[*-1] / @lhs[*-2] {
$next = { $_ * (@lhs[*-2] / @lhs[*-3]) };
} else {
fail "Unable to figure out pattern of series";
}
}
default { fail "Unable to figure out pattern of series"; }
}
}

Expand All @@ -431,11 +431,10 @@ our multi sub infix:<...>(@lhs is copy, $rhs) {
my @args;
my $j;
my $top = $arity min @lhs.elems;
for 0..^$top -> $i {
$j = @lhs[$i];
my $jj = $j;
take $jj;
@args.push($jj);
for @lhs.kv -> $i, $v {
$j = $v;
take $v;
@args.push($v) if $i >= @lhs.elems - $top;
}

if !$limit.defined || $limit cmp $j != 0 {
Expand Down

0 comments on commit 1eef087

Please sign in to comment.