rename InvokeNextPredicate to ConsiderPropositon
[scpubgit/DX.git] / lib / DX / Step / Normal.pm
index 10c4eb9..cff9543 100644 (file)
@@ -30,17 +30,27 @@ 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;
-  my $ns = DX::Step::InvokeNextPredicate->new(
-    proposition => $ss->next_proposition($new_hyp)
-  );
+  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} ])
+        : ()
+      ),
     ),
-    $self->alternative_step
   );
 }