1 package DX::SearchState;
3 use Types::Standard qw(Maybe);
4 use DX::Step::InvokeNextPredicate;
7 has current_hypothesis => (is => 'ro', isa => Hypothesis, required => 1);
9 has next_step => (is => 'ro', isa => Maybe[Step]);
11 has propositions => (is => 'ro', isa => PropositionSequence, required => 1);
13 has alternatives => (is => 'ro', isa => AlternativeList, required => 1);
15 sub next_proposition {
16 my ($self, $hyp) = @_;
17 $hyp ||= $self->current_hypothesis;
18 $self->propositions->members->[
19 $hyp->resolved_propositions->resolved_count
24 my ($class, $hyp, $props) = @_;
26 current_hypothesis => $hyp,
28 next_step => DX::Step::InvokeNextPredicate->new(
29 proposition => $props->members->[0],
31 propositions => $props,
37 my $hyp = $self->current_hypothesis;
38 return undef unless my $step = $self->next_step;
39 my ($first_alt, @rest_alt) = my @alt = @{$self->alternatives};
40 my ($new_ss, $alt_step) = $step->apply_to($self);
41 my $new_hyp = ($new_ss ? $new_ss->current_hypothesis : undef);
44 current_hypothesis => $new_hyp,
51 next_step => DX::Step::InvokeNextPredicate->new(
52 proposition => $self->next_proposition($new_hyp),
57 return $self->but(next_step => $alt_step);
59 return undef unless $first_alt;
60 trace 'search.backtrack.rewind_to' => $first_alt->[1];
62 current_hypothesis => $first_alt->[0],
63 alternatives => \@rest_alt,
64 next_step => $first_alt->[1],
70 my ($first_alt, @rest_alt) = @{$self->alternatives};
71 return undef unless $first_alt;
72 trace 'search.backtrack.forced' => $first_alt->[0];
73 return ref($self)->new(
74 current_hypothesis => $first_alt->[0],
75 next_step => $first_alt->[1],
76 alternatives => \@rest_alt,
77 propositions => $self->propositions,