Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix right-associative triangle reduce, decontainerization
  • Loading branch information
sorear committed Feb 18, 2011
1 parent f79241a commit ace95a1
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/SAFE.setting
Expand Up @@ -862,13 +862,14 @@ sub reduceop($triangle, $list, $right, $chain, $func, *@items) {
my $last = shift @items;
while @items {
my $next = shift @items;
take ($ok &&= $func($last, $next));
my $val ::= ($ok &&= $func($last, $next));
take $val;
$last = $next;
}
}
}
}
elsif $list || $right {
elsif $list {
my @pool;
gather {
while @items {
Expand All @@ -877,14 +878,28 @@ sub reduceop($triangle, $list, $right, $chain, $func, *@items) {
}
}
}
elsif $right {
gather {
while @items >= 2 {
my $right ::= @items.pop;
take $right;
my $left = @items.pop;
@items.push($func($left,$right));
}
if @items {
my $last ::= @items.shift;
take $last;
}
}
}
else { # left assoc
gather {
if @items {
my $cumu = @items.shift;
my $cumu ::= @items.shift;
take $cumu;
while @items {
$cumu = $func($cumu, @items.shift);
take $cumu;
my $new ::= ($cumu ::= $func($cumu, @items.shift));
take $new;
}
}
}
Expand Down

0 comments on commit ace95a1

Please sign in to comment.