]> Repositorios git - scryer-prolog.git/commitdiff
use can_be(list, _) in all solutions predicates
authorMark Thom <[email protected]>
Sat, 30 Mar 2019 16:44:49 +0000 (10:44 -0600)
committerMark Thom <[email protected]>
Sat, 30 Mar 2019 16:44:49 +0000 (10:44 -0600)
Cargo.toml
src/prolog/heap_print.rs
src/prolog/lib/builtins.pl
src/prolog/machine/toplevel.rs
src/tests.rs

index fa7e82432ff75dc9914ef1b9a4f2126c3cc7a6e0..a5b3a0bf0e1d1882270974a37fa7bd4a2a356e34 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.23"
+version = "0.8.24"
 authors = ["Mark Thom <[email protected]>"]
 repository = "https://github.com/mthom/scryer-prolog"
 description = "A modern Prolog implementation written mostly in Rust."
index d13aa8e98c20b9afec5f1571e77625b86855aaf9..dbef0a5311cb2aab1a653a02ec0c3e86cbb30b40 100644 (file)
@@ -56,7 +56,7 @@ impl<'a> HCPreOrderIterator<'a> {
     /*
      * descend into the subtree where the iterator is currently parked
      * and check that the leftmost leaf is a number, with every node
-     * encountered on the way an infix or postfix operator, and not blocked
+     * encountered on the way an infix or postfix operator, unblocked
      * by brackets.
      */
     fn leftmost_leaf_is_positive_number(&self) -> bool {
index e612dd8efd6eeff1a0a4c97b1af094580aa4de1c..ce95a2561c347954ce3e73c5ba0957527366c52a 100644 (file)
@@ -376,13 +376,8 @@ throw(Ball) :- '$set_ball'(Ball), '$unwind_stack'.
 
 truncate_lh_to(LhLength) :- '$truncate_lh_to'(LhLength).
 
-check_for_compat_list(L, PI) :-
-    (  nonvar(L), L \= [_|_], throw(error(type_error(list, L), PI))
-    ;  true
-    ).
-
 findall(Template, Goal, Solutions) :-
-    check_for_compat_list(Solutions, findall/3),
+    error:can_be(list, Solutions),
     '$lh_length'(LhLength),
     '$call_with_default_policy'(catch('$iterate_find_all'(Template, Goal, Solutions, LhLength),
                                      Error,
@@ -399,8 +394,8 @@ findall(Template, Goal, Solutions) :-
 
 
 findall(Template, Goal, Solutions0, Solutions1) :-
-    check_for_compat_list(Solutions0, findall/4),
-    check_for_compat_list(Solutions1, findall/4),
+    error:can_be(list, Solutions0),
+    error:can_be(list, Solutions1),
     '$lh_length'(LhLength),
     '$call_with_default_policy'(catch('$iterate_find_all_diff'(Template, Goal, Solutions0,
                                                               Solutions1, LhLength),
@@ -430,7 +425,7 @@ iterate_variants([_|GroupSolutions], Ws, Solution) :-
     iterate_variants(GroupSolutions, Ws, Solution).
 
 bagof(Template, Goal, Solution) :-
-    check_for_compat_list(Solution, bagof/3),
+    error:can_be(list, Solution),
     term_variables(Template, TemplateVars0),
     term_variables(Goal, GoalVars0),
     sort(TemplateVars0, TemplateVars),
@@ -447,7 +442,7 @@ iterate_variants_and_sort([_|GroupSolutions], Ws, Solution) :-
     iterate_variants_and_sort(GroupSolutions, Ws, Solution).
 
 setof(Template, Goal, Solution) :-
-    check_for_compat_list(Solution, setof/3),
+    error:can_be(list, Solution),
     term_variables(Template, TemplateVars0),
     term_variables(Goal, GoalVars0),
     sort(TemplateVars0, TemplateVars),
index c956cd8a41f54c3e17d69a40dbf356892a95ddae..cb1efed00889a16a84480f4c553c3e5780192cd9 100644 (file)
@@ -234,7 +234,7 @@ fn setup_qualified_import(mut terms: Vec<Box<Term>>) -> Result<UseModuleExport,
 fn setup_declaration(mut terms: Vec<Box<Term>>) -> Result<Declaration, ParserError>
 {
     let term = *terms.pop().unwrap();
-    
+
     match term {
         Term::Clause(_, name, mut terms, _) =>
             if name.as_str() == "op" && terms.len() == 3 {
@@ -405,7 +405,7 @@ impl RelationWorker {
                 if assume_dyn {
                     self.dynamic_clauses.push((term.clone(), tail));
                 }
-                
+
                 Ok(term)
             },
             _ =>
@@ -691,7 +691,7 @@ impl RelationWorker {
                         Ok(decl) => return Ok(TopLevel::Declaration(decl)),
                         _ => {}
                     };
-                    
+
                     Ok(TopLevel::Query(self.setup_query(indices, terms, blocks_cuts)?))
                 } else if name.as_str() == ":-" && terms.len() == 2 {
                     Ok(TopLevel::Rule(self.setup_rule(indices, terms, blocks_cuts, true)?))
index a470bfd7028af98dd1445899163b1f3fabdb21be..e854f153be277f6a8f66e35e58159e361a181486 100644 (file)
@@ -1721,7 +1721,7 @@ fn test_queries_on_builtins()
     assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 2), S).",
                            [["S = [1, 2]", "X = _0"]]);
     assert_prolog_success!(&mut wam, "?- findall(X+Y, (X = 1), S).",
-                           [["S = [1+_33]", "X = _1", "Y = _2"]]);
+                           [["S = [1+_36]", "X = _1", "Y = _2"]]);
     assert_prolog_success!(&mut wam, "?- findall(X, false, S).",
                            [["S = []", "X = _0"]]);
     assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 1), S).",
@@ -1750,12 +1750,12 @@ fn test_queries_on_builtins()
 
     assert_prolog_success!(&mut wam, "?- bagof(X, (X=Y; X=Z; Y=1), L).",
                            [["L = [_3, _6]", "X = _0", "Y = _3", "Z = _6"],
-                            ["L = [_178]", "X = _0", "Y = 1", "Z = _6"]]);
+                            ["L = [_184]", "X = _0", "Y = 1", "Z = _6"]]);
 
     submit(&mut wam, "a(1, f(_)). a(2, f(_)).");
 
     assert_prolog_success!(&mut wam, "?- bagof(X, a(X, Y), L).",
-                           [["L = [1, 2]", "X = _0", "Y = f(_144)"]]);
+                           [["L = [1, 2]", "X = _0", "Y = f(_150)"]]);
 
     assert_prolog_success!(&mut wam, "?- setof(X, (X = 1 ; X = 2), S).",
                            [["S = [1, 2]", "X = _0"]]);
@@ -1767,7 +1767,7 @@ fn test_queries_on_builtins()
                             ["L = [1]", "Y = 2"]]);
     assert_prolog_success!(&mut wam, "?- setof(X, (X=Y; X=Z; Y=1), L).",
                            [["L = [_3, _6]", "X = _0", "Y = _3", "Z = _6"],
-                            ["L = [_178]", "X = _0", "Y = 1", "Z = _6"]]);
+                            ["L = [_184]", "X = _0", "Y = 1", "Z = _6"]]);
     assert_prolog_failure!(&mut wam, "?- setof(X, member(X, [f(U,b),f(V,c)]), [f(a,c),f(a,b)]).");
     assert_prolog_success!(&mut wam, "?- setof(X, member(X, [f(U,b),f(V,c)]), [f(a,b),f(a,c)]).",
                            [["U = a", "V = a", "X = _0"]]);
@@ -1779,7 +1779,7 @@ fn test_queries_on_builtins()
     assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 2), S0, S1).",
                            [["S0 = [1, 2 | _11]", "S1 = _11", "X = _0"]]);
     assert_prolog_success!(&mut wam, "?- findall(X+Y, (X = 1), S0, S1).",
-                           [["S0 = [1+_38 | _7]", "S1 = _7", "X = _1", "Y = _2"]]);
+                           [["S0 = [1+_44 | _7]", "S1 = _7", "X = _1", "Y = _2"]]);
     assert_prolog_success!(&mut wam, "?- findall(X, false, S, _).",
                            [["S = []", "X = _0"]]);
     assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 1), S0, S1).",