From: Markus Triska Date: Fri, 8 Sep 2023 20:47:59 +0000 (+0200) Subject: shorter partition/5, relying on first instantiated argument indexing X-Git-Tag: remove~104^2~3 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=ec67752db480c5c9b96711ade6f5d72f6d433471;p=scryer-prolog.git shorter partition/5, relying on first instantiated argument indexing --- diff --git a/src/lib/clpb.pl b/src/lib/clpb.pl index b5deff81..d2e63db0 100644 --- a/src/lib/clpb.pl +++ b/src/lib/clpb.pl @@ -1969,17 +1969,16 @@ exclude(Goal, [L|Ls0], Ls) :- ), exclude(Goal, Ls0, Rest). -partition(Pred, List, Less, Equal, Greater) :- - partition_(List, Pred, Less, Equal, Greater). +:- meta_predicate(partition(2,?,?,?,?)). -partition_([], _, [], [], []). -partition_([H|T], Pred, L, E, G) :- +partition(_, [], [], [], []). +partition(Pred, [H|T], L, E, G) :- call(Pred, H, Diff), partition_(Diff, H, Pred, T, L, E, G). partition_(<, H, Pred, T, [H|Rest], E, G) :- - partition_(T, Pred, Rest, E, G). + partition(Pred, T, Rest, E, G). partition_(=, H, Pred, T, L, [H|Rest], G) :- - partition_(T, Pred, L, Rest, G). + partition(Pred, T, L, Rest, G). partition_(>, H, Pred, T, L, E, [H|Rest]) :- - partition_(T, Pred, L, E, Rest). + partition(Pred, T, L, E, Rest).