add correct error sources to bagof/3, setof/3, findall/4
This commit is contained in:
@@ -363,14 +363,14 @@ throw(Ball) :- '$set_ball'(Ball), '$unwind_stack'.
|
|||||||
|
|
||||||
truncate_lh_to(LhLength) :- '$truncate_lh_to'(LhLength).
|
truncate_lh_to(LhLength) :- '$truncate_lh_to'(LhLength).
|
||||||
|
|
||||||
check_for_compat_list(L) :-
|
check_for_compat_list(L, PI) :-
|
||||||
'$skip_max_list'(_, -1, L, R),
|
'$skip_max_list'(_, -1, L, R),
|
||||||
( nonvar(R), R \== [], throw(error(type_error(list, L), findall/3))
|
( nonvar(R), R \== [], throw(error(type_error(list, L), PI))
|
||||||
; true
|
; true
|
||||||
).
|
).
|
||||||
|
|
||||||
findall(Template, Goal, Solutions) :-
|
findall(Template, Goal, Solutions) :-
|
||||||
check_for_compat_list(Solutions),
|
check_for_compat_list(Solutions, findall/3),
|
||||||
'$lh_length'(LhLength),
|
'$lh_length'(LhLength),
|
||||||
'$call_with_default_policy'(catch('$iterate_find_all'(Template, Goal, Solutions, LhLength),
|
'$call_with_default_policy'(catch('$iterate_find_all'(Template, Goal, Solutions, LhLength),
|
||||||
Error,
|
Error,
|
||||||
@@ -387,8 +387,8 @@ findall(Template, Goal, Solutions) :-
|
|||||||
|
|
||||||
|
|
||||||
findall(Template, Goal, Solutions0, Solutions1) :-
|
findall(Template, Goal, Solutions0, Solutions1) :-
|
||||||
check_for_compat_list(Solutions0),
|
check_for_compat_list(Solutions0, findall/4),
|
||||||
check_for_compat_list(Solutions1),
|
check_for_compat_list(Solutions1, findall/4),
|
||||||
'$lh_length'(LhLength),
|
'$lh_length'(LhLength),
|
||||||
'$call_with_default_policy'(catch('$iterate_find_all_diff'(Template, Goal, Solutions0,
|
'$call_with_default_policy'(catch('$iterate_find_all_diff'(Template, Goal, Solutions0,
|
||||||
Solutions1, LhLength),
|
Solutions1, LhLength),
|
||||||
@@ -418,7 +418,7 @@ iterate_variants([_|GroupSolutions], Ws, Solution) :-
|
|||||||
iterate_variants(GroupSolutions, Ws, Solution).
|
iterate_variants(GroupSolutions, Ws, Solution).
|
||||||
|
|
||||||
bagof(Template, Goal, Solution) :-
|
bagof(Template, Goal, Solution) :-
|
||||||
check_for_compat_list(Solution),
|
check_for_compat_list(Solution, bagof/3),
|
||||||
term_variables(Template, TemplateVars0),
|
term_variables(Template, TemplateVars0),
|
||||||
term_variables(Goal, GoalVars0),
|
term_variables(Goal, GoalVars0),
|
||||||
sort(TemplateVars0, TemplateVars),
|
sort(TemplateVars0, TemplateVars),
|
||||||
@@ -435,6 +435,7 @@ iterate_variants_and_sort([_|GroupSolutions], Ws, Solution) :-
|
|||||||
iterate_variants_and_sort(GroupSolutions, Ws, Solution).
|
iterate_variants_and_sort(GroupSolutions, Ws, Solution).
|
||||||
|
|
||||||
setof(Template, Goal, Solution) :-
|
setof(Template, Goal, Solution) :-
|
||||||
|
check_for_compat_list(Solution, setof/3),
|
||||||
term_variables(Template, TemplateVars0),
|
term_variables(Template, TemplateVars0),
|
||||||
term_variables(Goal, GoalVars0),
|
term_variables(Goal, GoalVars0),
|
||||||
sort(TemplateVars0, TemplateVars),
|
sort(TemplateVars0, TemplateVars),
|
||||||
|
|||||||
10
src/tests.rs
10
src/tests.rs
@@ -1715,7 +1715,7 @@ fn test_queries_on_builtins()
|
|||||||
assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 2), S).",
|
assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 2), S).",
|
||||||
[["S = [1, 2]", "X = _0"]]);
|
[["S = [1, 2]", "X = _0"]]);
|
||||||
assert_prolog_success!(&mut wam, "?- findall(X+Y, (X = 1), S).",
|
assert_prolog_success!(&mut wam, "?- findall(X+Y, (X = 1), S).",
|
||||||
[["S = [1+_31]", "X = _1", "Y = _2"]]);
|
[["S = [1+_35]", "X = _1", "Y = _2"]]);
|
||||||
assert_prolog_success!(&mut wam, "?- findall(X, false, S).",
|
assert_prolog_success!(&mut wam, "?- findall(X, false, S).",
|
||||||
[["S = []", "X = _0"]]);
|
[["S = []", "X = _0"]]);
|
||||||
assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 1), S).",
|
assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 1), S).",
|
||||||
@@ -1744,12 +1744,12 @@ fn test_queries_on_builtins()
|
|||||||
|
|
||||||
assert_prolog_success!(&mut wam, "?- bagof(X, (X=Y; X=Z; Y=1), L).",
|
assert_prolog_success!(&mut wam, "?- bagof(X, (X=Y; X=Z; Y=1), L).",
|
||||||
[["L = [_3, _6]", "X = _0", "Y = _3", "Z = _6"],
|
[["L = [_3, _6]", "X = _0", "Y = _3", "Z = _6"],
|
||||||
["L = [_174]", "X = _0", "Y = 1", "Z = _6"]]);
|
["L = [_182]", "X = _0", "Y = 1", "Z = _6"]]);
|
||||||
|
|
||||||
submit(&mut wam, "a(1, f(_)). a(2, f(_)).");
|
submit(&mut wam, "a(1, f(_)). a(2, f(_)).");
|
||||||
|
|
||||||
assert_prolog_success!(&mut wam, "?- bagof(X, a(X, Y), L).",
|
assert_prolog_success!(&mut wam, "?- bagof(X, a(X, Y), L).",
|
||||||
[["L = [1, 2]", "X = _0", "Y = f(_140)"]]);
|
[["L = [1, 2]", "X = _0", "Y = f(_148)"]]);
|
||||||
|
|
||||||
assert_prolog_success!(&mut wam, "?- setof(X, (X = 1 ; X = 2), S).",
|
assert_prolog_success!(&mut wam, "?- setof(X, (X = 1 ; X = 2), S).",
|
||||||
[["S = [1, 2]", "X = _0"]]);
|
[["S = [1, 2]", "X = _0"]]);
|
||||||
@@ -1761,7 +1761,7 @@ fn test_queries_on_builtins()
|
|||||||
["L = [1]", "Y = 2"]]);
|
["L = [1]", "Y = 2"]]);
|
||||||
assert_prolog_success!(&mut wam, "?- setof(X, (X=Y; X=Z; Y=1), L).",
|
assert_prolog_success!(&mut wam, "?- setof(X, (X=Y; X=Z; Y=1), L).",
|
||||||
[["L = [_3, _6]", "X = _0", "Y = _3", "Z = _6"],
|
[["L = [_3, _6]", "X = _0", "Y = _3", "Z = _6"],
|
||||||
["L = [_173]", "X = _0", "Y = 1", "Z = _6"]]);
|
["L = [_182]", "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_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)]).",
|
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"]]);
|
[["U = a", "V = a", "X = _0"]]);
|
||||||
@@ -1773,7 +1773,7 @@ fn test_queries_on_builtins()
|
|||||||
assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 2), S0, S1).",
|
assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 2), S0, S1).",
|
||||||
[["S0 = [1, 2 | _11]", "S1 = _11", "X = _0"]]);
|
[["S0 = [1, 2 | _11]", "S1 = _11", "X = _0"]]);
|
||||||
assert_prolog_success!(&mut wam, "?- findall(X+Y, (X = 1), S0, S1).",
|
assert_prolog_success!(&mut wam, "?- findall(X+Y, (X = 1), S0, S1).",
|
||||||
[["S0 = [1+_34 | _7]", "S1 = _7", "X = _1", "Y = _2"]]);
|
[["S0 = [1+_42 | _7]", "S1 = _7", "X = _1", "Y = _2"]]);
|
||||||
assert_prolog_success!(&mut wam, "?- findall(X, false, S, _).",
|
assert_prolog_success!(&mut wam, "?- findall(X, false, S, _).",
|
||||||
[["S = []", "X = _0"]]);
|
[["S = []", "X = _0"]]);
|
||||||
assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 1), S0, S1).",
|
assert_prolog_success!(&mut wam, "?- findall(X, (X = 1 ; X = 1), S0, S1).",
|
||||||
|
|||||||
Reference in New Issue
Block a user