]> Repositorios git - scryer-prolog.git/commitdiff
add predicates to lists.pl
authorMark Thom <[email protected]>
Mon, 2 Dec 2019 02:30:40 +0000 (19:30 -0700)
committerMark Thom <[email protected]>
Mon, 2 Dec 2019 02:30:40 +0000 (19:30 -0700)
README.md
src/prolog/lib/lists.pl

index 636144990af309e21867594a95f839a9efe53904..2d060807dfe11829c2fe70ccd2c3c6022f538316 100644 (file)
--- a/README.md
+++ b/README.md
@@ -186,6 +186,7 @@ The following predicates are built-in to Scryer.
 * `false/0`
 * `findall/{3,4}`
 * `float/1`
+* `foldl/{4,5}`
 * `forall/2`
 * `freeze/2`
 * `functor/3`
@@ -219,6 +220,7 @@ The following predicates are built-in to Scryer.
 * `repeat/{0,1}`
 * `retract/1`
 * `reverse/2`
+* `same_length/2`
 * `select/3`
 * `setof/3`
 * `setup_call_cleanup/3`
@@ -226,6 +228,7 @@ The following predicates are built-in to Scryer.
 * `string/1`
 * `sub_atom/5`
 * `subsumes_term/2`
+* `sumlist/2`
 * `term_expansion/2`
 * `term_variables/2`
 * `throw/1`
index f3a4ef6b2dd451df0e0e92944ecb7ea526095faa..153b90ff8d56b40b1fa0f256baacaae96f9b522a 100644 (file)
@@ -1,7 +1,8 @@
-:- module(lists, [member/2, select/3, append/3, memberchk/2,
-                 reverse/2, length/2, maplist/2, maplist/3,
-                 maplist/4, maplist/5, maplist/6, maplist/7,
-                 maplist/8, maplist/9, sumlist/2]).
+:- module(lists, [member/2, select/3, append/3, foldl/4, foldl/5,
+                 memberchk/2, reverse/2, length/2, maplist/2,
+                 maplist/3, maplist/4, maplist/5, maplist/6,
+                 maplist/7, maplist/8, maplist/9, same_length/2,
+                 sumlist/2]).
 
 
 :- use_module(library(error)).
@@ -109,3 +110,27 @@ sumlist_([N|Ns], S, S0) :-
 sumlist(Ns, S) :-
     must_be(list, Ns),
     sumlist_(Ns, S, 0).
+
+
+
+same_length([], []).
+same_length([_|As], [_|Bs]) :-
+        same_length(As, Bs).
+
+
+foldl(Goal_3, Ls, A0, A) :-
+        foldl_(Ls, Goal_3, A0, A).
+
+foldl_([], _, A, A).
+foldl_([L|Ls], G_3, A0, A) :-
+        call(G_3, L, A0, A1),
+        foldl_(Ls, G_3, A1, A).
+
+
+foldl(Goal_4, Xs, Ys, A0, A) :-
+        foldl_(Xs, Ys, Goal_4, A0, A).
+
+foldl_([], [], _, A, A).
+foldl_([X|Xs], [Y|Ys], G_4, A0, A) :-
+        call(G_4, X, Y, A0, A1),
+        foldl_(Xs, Ys, G_4, A1, A).