From 5a08117e7591b65ebbf106f0e9bc72b3adeadb7f Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Wed, 20 Jul 2022 21:16:17 -0600 Subject: [PATCH] use separate predicate for findall cleanup --- src/lib/builtins.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/builtins.pl b/src/lib/builtins.pl index 8e4553ce..dd7fb547 100644 --- a/src/lib/builtins.pl +++ b/src/lib/builtins.pl @@ -690,6 +690,12 @@ truncate_lh_to(LhLength) :- '$truncate_lh_to'(LhLength). :- meta_predicate findall(?, 0, ?). +:- non_counted_backtracking findall_cleanup/2. + +findall_cleanup(LhLength, Error) :- + truncate_lh_to(LhLength), + throw(Error). + :- non_counted_backtracking findall/3. findall(Template, Goal, Solutions) :- @@ -697,7 +703,7 @@ findall(Template, Goal, Solutions) :- '$lh_length'(LhLength), catch(builtins:'$iterate_find_all'(Template, Goal, Solutions, LhLength), Error, - ( builtins:truncate_lh_to(LhLength), builtins:throw(Error) ) + builtins:findall_cleanup(LhLength, Error) ). :- non_counted_backtracking '$iterate_find_all_diff'/5. @@ -722,7 +728,7 @@ findall(Template, Goal, Solutions0, Solutions1) :- catch(builtins:'$iterate_find_all_diff'(Template, Goal, Solutions0, Solutions1, LhLength), Error, - ( builtins:truncate_lh_to(LhLength), builtins:throw(Error) ) + builtins:findall_cleanup(LhLength, Error) ). :- non_counted_backtracking set_difference/3. -- 2.54.0