add predicates to lists.pl

This commit is contained in:
Mark Thom
2019-12-01 19:30:40 -07:00
parent c362cc6d34
commit 52488b875a
2 changed files with 32 additions and 4 deletions

View File

@@ -186,6 +186,7 @@ The following predicates are built-in to Scryer.
* `false/0` * `false/0`
* `findall/{3,4}` * `findall/{3,4}`
* `float/1` * `float/1`
* `foldl/{4,5}`
* `forall/2` * `forall/2`
* `freeze/2` * `freeze/2`
* `functor/3` * `functor/3`
@@ -219,6 +220,7 @@ The following predicates are built-in to Scryer.
* `repeat/{0,1}` * `repeat/{0,1}`
* `retract/1` * `retract/1`
* `reverse/2` * `reverse/2`
* `same_length/2`
* `select/3` * `select/3`
* `setof/3` * `setof/3`
* `setup_call_cleanup/3` * `setup_call_cleanup/3`
@@ -226,6 +228,7 @@ The following predicates are built-in to Scryer.
* `string/1` * `string/1`
* `sub_atom/5` * `sub_atom/5`
* `subsumes_term/2` * `subsumes_term/2`
* `sumlist/2`
* `term_expansion/2` * `term_expansion/2`
* `term_variables/2` * `term_variables/2`
* `throw/1` * `throw/1`

View File

@@ -1,7 +1,8 @@
:- module(lists, [member/2, select/3, append/3, memberchk/2, :- module(lists, [member/2, select/3, append/3, foldl/4, foldl/5,
reverse/2, length/2, maplist/2, maplist/3, memberchk/2, reverse/2, length/2, maplist/2,
maplist/4, maplist/5, maplist/6, maplist/7, maplist/3, maplist/4, maplist/5, maplist/6,
maplist/8, maplist/9, sumlist/2]). maplist/7, maplist/8, maplist/9, same_length/2,
sumlist/2]).
:- use_module(library(error)). :- use_module(library(error)).
@@ -109,3 +110,27 @@ sumlist_([N|Ns], S, S0) :-
sumlist(Ns, S) :- sumlist(Ns, S) :-
must_be(list, Ns), must_be(list, Ns),
sumlist_(Ns, S, 0). 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).