From 20675f56e65dddebe6b5ed970335cc975de390b0 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Tue, 26 May 2020 23:46:09 -0600 Subject: [PATCH] plug missing variables in equations (#488), exclude/3 regression (#452), incorrect answer substitution (#326) --- src/prolog/toplevel.pl | 56 ++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index d8f8e8fb..17561ece 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -238,7 +238,11 @@ write_eqs_and_read_input(B, VarList) :- charsio:extend_var_list(Vars, VarList, NewVarList, fabricated), '$get_b_value'(B0), gather_query_vars(VarList, OrigVars), - gather_equations(NewVarList, OrigVars, Goals, AttrGoals), + gather_equations(NewVarList, OrigVars, Equations), + append(Equations, AttrGoals, Goals), + term_variables(Equations, EqVars0), + append([EqVars0, AttrVars, AttrGoalVars], Vars1), + charsio:extend_var_list(Vars1, VarList, NewVarList0, fabricated), ( bb_get('$first_answer', true) -> write(' '), bb_put('$first_answer', false) @@ -248,13 +252,13 @@ write_eqs_and_read_input(B, VarList) :- ( Goals == [] -> write('true.'), nl ; thread_goals(Goals, ThreadedGoals, (',')), - write_eq(ThreadedGoals, NewVarList, 20), + write_eq(ThreadedGoals, NewVarList0, 20), write('.'), nl ) ; thread_goals(Goals, ThreadedGoals, (',')), - write_eq(ThreadedGoals, NewVarList, 20), - read_input(ThreadedGoals, NewVarList) + write_eq(ThreadedGoals, NewVarList0, 20), + read_input(ThreadedGoals, NewVarList0) ). read_input(ThreadedGoals, NewVarList) :- @@ -303,35 +307,30 @@ is_a_different_variable([_ = Binding | Pairs], Value) :- eq_member(X, [Y|_]) :- X == Y, !. eq_member(X, [_|Ys]) :- eq_member(X, Ys). -gather_equations([], _, Goals, Goals). -gather_equations([Var = Value | Pairs], OrigVarList, Goals, Goals1) :- +select_all([], _, _, [], []). +select_all([OtherVar = OtherValue | Pairs], Var, Value, Vars, NewPairs) :- + ( OtherValue == Value -> + Vars = [OtherVar = OtherValue | Vars0], + select_all(Pairs, Var, Value, Vars0, NewPairs) + ; + NewPairs = [OtherVar = OtherValue | NewPairs0], + select_all(Pairs, Var, Value, Vars, NewPairs0) + ). + +gather_equations([], _, []). +gather_equations([Var = Value | Pairs], OrigVarList, Goals) :- ( var(Value) -> ( eq_member(Value, OrigVarList), - ( Pairs == [], NewPairs = [] - ; ( select((OtherVar = OtherValue), Pairs, NewPairs), - Value == OtherValue, Var \== OtherVar - ) - ) -> - Goals = [Var = Value | Goals0], - gather_equations(NewPairs, OrigVarList, Goals0, Goals1) - ; gather_equations(Pairs, OrigVarList, Goals, Goals1) + select_all(Pairs, Var, Value, [_ | VarEqs], NewPairs) -> + append([Var = Value | VarEqs], Goals0, Goals), + gather_equations(NewPairs, OrigVarList, Goals0) + ; + gather_equations(Pairs, OrigVarList, Goals) ) - ; Goals = [Var = Value | Goals0], - gather_equations(Pairs, OrigVarList, Goals0, Goals1) - ). - -/* -gather_equations([], MasterList, Goals, Goals). -gather_equations([Var = Value | Pairs], MasterList, Goals, Goals1) :- - ( ( nonvar(Value) - ; select((Var = _), MasterList, MasterPairs), - is_a_different_variable(MasterPairs, Value) - ) -> + ; Goals = [Var = Value | Goals0], - gather_equations(Pairs, MasterList, Goals0, Goals1) - ; gather_equations(Pairs, MasterList, Goals, Goals1) + gather_equations(Pairs, OrigVarList, Goals0) ). -*/ print_exception(E) :- ( E == error('$interrupt_thrown', repl) -> nl % print the @@ -476,4 +475,3 @@ thread_goals(Goals0, Goals1, Functor) :- ) ; Goals1 = Goals0 ). - -- 2.54.0