]> Repositorios git - scryer-prolog.git/commitdiff
use separate predicate for findall cleanup
authorMark Thom <[email protected]>
Thu, 21 Jul 2022 03:16:17 +0000 (21:16 -0600)
committerMark Thom <[email protected]>
Thu, 27 Oct 2022 05:36:07 +0000 (23:36 -0600)
src/lib/builtins.pl

index 8e4553ce226d16194382b3a36b63d80fe997b0b1..dd7fb5470f3057eacb31a41d6f4ea95ea8d5daa0 100644 (file)
@@ -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.