rename InvokeNextPredicate to ConsiderPropositon
[scpubgit/DX.git] / lib / DX / Step / Normal.pm
index 350d4dc..cff9543 100644 (file)
@@ -30,9 +30,28 @@ sub apply_to {
   trace 'step.apply.old_hyp '.$self => $old_hyp;
   trace 'step.apply.actions '.$self => $self->actions;
   my $new_hyp = $self->_apply_to_hyp($old_hyp);
-  return (undef, $self->alternative_step) unless $new_hyp;
+  return $ss->but(next_step => DX::Step::Backtrack->new) unless $new_hyp;
   trace 'step.apply.new_hyp '.$self => $new_hyp;
-  return ($ss->but(current_hypothesis => $new_hyp), $self->alternative_step);
+  my $ns = do {
+    if (my $prop = $ss->next_proposition($new_hyp)) {
+      DX::Step::ConsiderProposition->new(
+        proposition => $prop
+      )
+    } else {
+      $ss->on_solution_step
+    }
+  };
+  my $alt_step = $self->alternative_step;
+  return (
+    $ss->but(
+      current_hypothesis => $new_hyp,
+      next_step => $ns,
+      ($alt_step
+        ? (alternatives => [ [ $old_hyp, $alt_step ], @{$ss->alternatives} ])
+        : ()
+      ),
+    ),
+  );
 }
 
 sub _apply_to_hyp {