]> Repositorios git - scryer-prolog.git/commitdiff
use select/3 in gather_equations for detecting whether variables are distinct.
authorMark Thom <[email protected]>
Mon, 4 May 2020 02:31:12 +0000 (20:31 -0600)
committerMark Thom <[email protected]>
Mon, 4 May 2020 02:31:12 +0000 (20:31 -0600)
src/prolog/machine/compile.rs
src/prolog/toplevel.pl

index 10bc4d229816fece72a3d3521926633e923eaa2a..64f56a30d53686e09732ba2e4f27ab715a55672c 100644 (file)
@@ -763,14 +763,14 @@ impl ListingCompiler {
     }
 
     fn generate_init_goal_code(
-       &mut self,
+           &mut self,
     ) -> Result<Code, SessionError> {
-       let query_terms = mem::replace(&mut self.initialization_goals.0, vec![]);
-       let queue = mem::replace(&mut self.initialization_goals.1, VecDeque::new());
+           let query_terms = mem::replace(&mut self.initialization_goals.0, vec![]);
+           let queue = mem::replace(&mut self.initialization_goals.1, VecDeque::new());
 
-       compile_query(query_terms, queue)
-           .map(|(code, _)| code)
-           .map_err(SessionError::from)
+           compile_query(query_terms, queue)
+               .map(|(code, _)| code)
+               .map_err(SessionError::from)
     }
 
     fn set_code_index(
@@ -1143,7 +1143,8 @@ impl ListingCompiler {
         result
     }
 
-    pub(crate) fn gather_items(
+    pub(crate)
+    fn gather_items(
         &mut self,
         wam: &mut Machine,
         src: &mut ParsingStream<Stream>,
@@ -1339,7 +1340,7 @@ fn compile_work_impl(
     let init_goal_code = compiler.generate_init_goal_code()?;
 
     if init_goal_code.len() > 0 {
-       if !wam.run_init_code(init_goal_code) {
+           if !wam.run_init_code(init_goal_code) {
             println!("Warning: initialization goal for {} failed",
                      compiler.listing_src.name());
         }
index a939a40d4088207b6975f02438cdc00f9ac9b77a..ed17f80ac9bdb4be129f60bbee7d202e79fca5a3 100644 (file)
@@ -235,7 +235,7 @@ write_eqs_and_read_input(B, VarList) :-
     append([Vars0, AttrVars, AttrGoalVars], Vars),
     charsio:extend_var_list(Vars, VarList, NewVarList, fabricated),
     '$get_b_value'(B0),
-    gather_equations(NewVarList, Goals, AttrGoals),
+    gather_equations(NewVarList, NewVarList, Goals, AttrGoals),
     (   bb_get('$first_answer', true) ->
         write('   '),
         bb_put('$first_answer', false)
@@ -294,17 +294,18 @@ gather_query_vars([], []).
 
 is_a_different_variable([_ = Binding | Pairs], Value) :-
     (  Value == Binding, !
-    ;  is_a_different_variable(Pairs, Value)
+    ;  is_a_different_variable(Pairs, Var)
     ).
 
-gather_equations([], Goals, Goals).
-gather_equations([Var = Value | Pairs], Goals, Goals1) :-
+gather_equations([], MasterList, Goals, Goals).
+gather_equations([Var = Value | Pairs], MasterList, Goals, Goals1) :-
+    select((Var = _), MasterList, MasterPairs),
     (  (  nonvar(Value)
-       ;  is_a_different_variable(Pairs, Value)
+       ;  is_a_different_variable(MasterPairs, Value)
        ) ->
        Goals = [Var = Value | Goals0],
-       gather_equations(Pairs, Goals0, Goals1)
-    ;  gather_equations(Pairs, Goals, Goals1)
+       gather_equations(Pairs, MasterList, Goals0, Goals1)
+    ;  gather_equations(Pairs, MasterList, Goals, Goals1)
     ).
 
 print_exception(E) :-