]> Repositorios git - scryer-prolog.git/commitdiff
shorter partition/5, relying on first instantiated argument indexing
authorMarkus Triska <[email protected]>
Fri, 8 Sep 2023 20:47:59 +0000 (22:47 +0200)
committerMarkus Triska <[email protected]>
Sat, 9 Sep 2023 05:32:06 +0000 (07:32 +0200)
src/lib/clpb.pl

index b5deff81c65d389c816b6d292846796dc7d89a80..d2e63db064381d5b5d3cbb121f0b64c35d5f29ec 100644 (file)
@@ -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).