From: Markus Triska Date: Fri, 8 Sep 2023 20:40:50 +0000 (+0200) Subject: shorter include/3 and exclude/3, relying on improved indexing X-Git-Tag: remove~104^2~5 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=672979c515703ad5c2aa2ef18b1c2451ced512a9;p=scryer-prolog.git shorter include/3 and exclude/3, relying on improved indexing --- diff --git a/src/lib/clpb.pl b/src/lib/clpb.pl index fdf1cfce..311d6115 100644 --- a/src/lib/clpb.pl +++ b/src/lib/clpb.pl @@ -1949,29 +1949,21 @@ Compatibility predicates. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -include(Goal, List, Is) :- - include_(List, Goal, Is). - -include_([], _, []). -include_([X1|Xs1], P, Is) :- - ( call(P, X1) - -> Is = [X1|Is1] - ; Is = Is1 +include(_, [], []). +include(Goal, [L|Ls0], Ls) :- + ( call(Goal, L) -> + Ls = [L|Rest] + ; Ls = Rest ), - include_(Xs1, P, Is1). + include(Goal, Ls0, Rest). - -exclude(Goal, List, Is) :- - exclude_(List, Goal, Is). - -exclude_([], _, []). -exclude_([X1|Xs1], P, Is) :- - ( call(P, X1) - -> Is = Is1 - ; Is = [X1|Is1] +exclude(_, [], []). +exclude(Goal, [L|Ls0], Ls) :- + ( call(Goal, L) -> + Ls = Rest + ; Ls = [L|Rest] ), - exclude_(Xs1, P, Is1). - + exclude(Goal, Ls0, Rest). partition(Pred, List, Less, Equal, Greater) :- partition_(List, Pred, Less, Equal, Greater).