]> git.vpit.fr Git - perl/modules/Sub-Nary.git/commitdiff
Fix handling of partial returns in lists
authorVincent Pit <vince@profvince.com>
Fri, 8 Aug 2008 19:43:41 +0000 (21:43 +0200)
committerVincent Pit <vince@profvince.com>
Fri, 8 Aug 2008 19:43:41 +0000 (21:43 +0200)
lib/Sub/Nary.pm
t/20-return.t

index 50ba378034fa54a17ab6a2e4366926528aa3e52f..b6ad798ebbe50604af0198ef7d183e8ebb90e5f2 100644 (file)
@@ -311,18 +311,20 @@ sub inspect_kids {
    $op = $op->first;
    redo;
   }
    $op = $op->first;
    redo;
   }
-  diag "> $n ($c)" if $DEBUG;
+  diag "> $n" if $DEBUG;
   my ($rc, $lc) = $self->inspect($op);
   my ($rc, $lc) = $self->inspect($op);
+  $c = 1 - count $r;
+  diag Dumper [ $c, $r, \@l, $rc, $lc ] if $DEBUG;
   $r = add $r, scale $c, $rc if defined $rc;
   $r = add $r, scale $c, $rc if defined $rc;
-  if ($rc and not defined $lc) {
+  if (not defined $lc) {
    @l = ();
    last;
   }
   push @l, scale $c, $lc;
    @l = ();
    last;
   }
   push @l, scale $c, $lc;
-  $c *= count $lc if defined $lc;
  }
 
  }
 
- my $l = combine @l;
+# diag Dumper \@l if $DEBUG;
+ my $l = scale +(1 - count $r), normalize combine @l;
 
  return $r, $l;
 }
 
  return $r, $l;
 }
index c48eeeff15c3bef5c82b140f0031fe94b58b2b5b..ccfd9e9fa2a0aaf8df73a912e5bb54677899507f 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
 use strict;
 use warnings;
 
-use Test::More tests => 76;
+use Test::More tests => 79;
 
 use Sub::Nary;
 
 
 use Sub::Nary;
 
@@ -25,6 +25,10 @@ my @tests = (
  [ sub { do { 1; return 2, 3 } },              2 ],
  [ sub { do { 1; return 2, 3; 4 } },           2 ],
  [ sub { do { 1; return 2, return 3 } },       1 ],
  [ sub { do { 1; return 2, 3 } },              2 ],
  [ sub { do { 1; return 2, 3; 4 } },           2 ],
  [ sub { do { 1; return 2, return 3 } },       1 ],
+ [ sub { do { return if $x; 2, 3 }, 4 },       { 0 => 0.5, 3 => 0.5 } ],
+ [ sub { do { do { return if $x }, 3 }, 4 },   { 0 => 0.5, 3 => 0.5 } ],
+ [ sub { do { return if $x; 2, 3 }, do { return 1 if $y; 4, 5, 6 } },
+                                           { 0 => 0.5, 1 => 0.25, 5 => 0.25 } ],
 
  [ sub { return $x },     1 ],
  [ sub { return $x, $y }, 2 ],
 
  [ sub { return $x },     1 ],
  [ sub { return $x, $y }, 2 ],