[m-rev.] diff: add list.foldl_corresponding3/6 etc
Julien Fischer
juliensf at csse.unimelb.edu.au
Thu Jan 4 15:53:48 AEDT 2007
I've found a need for the following while converting more of the HLDS
to use proc_arg_vectors instead of lists.
Estimated hours taken: 0.5
Branches: main
library/list.m:
Add several new higher-order predicates for performing folds
over three corresponding lists: list.foldl_corresponding3/6,
list.foldl2_corresponding3/8 and list.foldl3_corresponding3/10.
Fix a comment.
NEWS:
Merge the existing entries for the list module into a single entry.
Mention the new predicates.
Julien.
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.434
diff -u -r1.434 NEWS
--- NEWS 2 Jan 2007 07:37:54 -0000 1.434
+++ NEWS 4 Jan 2007 04:01:07 -0000
@@ -15,18 +15,21 @@
Changes to the Mercury standard library:
-* We have added list.map_corresponding/4, a predicate version of
- list.map_corresponding/3.
+* The following predicates have been added to the list module:
+ list.map_corresponding/4
+ list.map2_foldl3/10
+ list.map_corresponding_foldl/6
+ list.map_corresponding3_foldl/7
+ list.foldl_corresponding3/6
+ list.foldl2_corresponding3/8
+ list.foldl3_corresponding3/10
-* We have added versions of list.foldl/4 and list.foldr/4 that have
- determinism multi.
+ We have also added versions of list.foldl/4 and list.foldr/4 that have
+ determinism multi.
* We have changed the interface of the ops module to make lookups of operators
more efficient.
-* We have added list.map2_foldl3/10, list.map_corresponding_foldl/6 and
- list.map_corresponding3_foldl/7
-
* We have added io.update_globals/3 which allows for atomic updates to
the globals field in the I/O state in the presence of multiple threads.
Index: library/list.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.158
diff -u -r1.158 list.m
--- library/list.m 2 Jan 2007 07:37:54 -0000 1.158
+++ library/list.m 4 Jan 2007 03:55:58 -0000
@@ -634,7 +634,7 @@
:- mode list.map_corresponding_foldl(pred(in, in, out, di, uo) is det,
in, in, out, di, uo) is det.
- % list.map_corresponding3_foldl7 is like list.map_corresponding3 except
+ % list.map_corresponding3_foldl/7 is like list.map_corresponding3 except
% that it has an accumulator threaded through it.
%
:- pred list.map_corresponding3_foldl(pred(A, B, C, D, E, E),
@@ -833,6 +833,47 @@
:- mode list.foldl2_corresponding(pred(in, in, in, out, di, uo) is cc_multi,
in, in, in, out, di, uo) is cc_multi.
+ % list.foldl_corresponding3(P, As, Bs, Cs, !Acc):
+ % Like list.foldl_corresponding but folds over three corresponding
+ % lists.
+ %
+:- pred list.foldl_corresponding3(pred(A, B, C, D, D),
+ list(A), list(B), list(C), D, D).
+:- mode list.foldl_corresponding3(pred(in, in, in, in, out) is det,
+ in, in, in, in, out) is det.
+:- mode list.foldl_corresponding3(pred(in, in, in, di, uo) is det,
+ in, in, in, di, uo) is det.
+:- mode list.foldl_corresponding3(pred(in, in, in, in, out) is semidet,
+ in, in, in, in, out) is semidet.
+
+ % list.foldl2_corresponding3(P, As, Bs, Cs, !Acc1, !Acc2):
+ % like list.foldl_corresponding3 but with two accumulators.
+ %
+:- pred list.foldl2_corresponding3(pred(A, B, C, D, D, E, E),
+ list(A), list(B), list(C), D, D, E, E).
+:- mode list.foldl2_corresponding3(pred(in, in, in, in, out, in, out) is det,
+ in, in, in, in, out, in, out) is det.
+:- mode list.foldl2_corresponding3(pred(in, in, in, in, out, di, uo) is det,
+ in, in, in, in, out, di, uo) is det.
+:- mode list.foldl2_corresponding3(
+ pred(in, in, in, in, out, in, out) is semidet,
+ in, in, in, in, out, in, out) is semidet.
+
+ % list.foldl3_corresponding3(P, As, Bs, Cs, !Acc1, !Acc2, !Acc3):
+ % like list.foldl_corresponding3 but with three accumulators.
+ %
+:- pred list.foldl3_corresponding3(pred(A, B, C, D, D, E, E, F, F),
+ list(A), list(B), list(C), D, D, E, E, F, F).
+:- mode list.foldl3_corresponding3(
+ pred(in, in, in, in, out, in, out, in, out) is det,
+ in, in, in, in, out, in, out, in, out) is det.
+:- mode list.foldl3_corresponding3(
+ pred(in, in, in, in, out, in, out, di, uo) is det,
+ in, in, in, in, out, in, out, di, uo) is det.
+:- mode list.foldl3_corresponding3(
+ pred(in, in, in, in, out, in, out, in, out) is semidet,
+ in, in, in, in, out, in, out, in, out) is semidet.
+
% list.map_foldl(Pred, InList, OutList, Start, End) calls Pred
% with an accumulator (with the initial value of Start) on
% each element of InList (working left-to-right) to transform
@@ -1947,6 +1988,59 @@
P(A, B, !Acc1, !Acc2),
list.foldl2_corresponding(P, As, Bs, !Acc1, !Acc2).
+list.foldl_corresponding3(_, [], [], [], !Acc).
+list.foldl_corresponding3(_, [_ | _], [], [], _, _) :-
+ error("list.foldl_corresponding3/6: mismatched list arguments").
+list.foldl_corresponding3(_, [], [_ | _], [], _, _) :-
+ error("list.foldl_corresponding3/6: mismatched list arguments").
+list.foldl_corresponding3(_, [], [], [_ | _], _, _) :-
+ error("list.foldl_corresponding3/6: mismatched list arguments").
+list.foldl_corresponding3(_, [], [_ | _], [_ | _], _, _) :-
+ error("list.foldl_corresponding3/6: mismatched list arguments").
+list.foldl_corresponding3(_, [_ | _], [], [_ | _], _, _) :-
+ error("list.foldl_corresponding3/6: mismatched list arguments").
+list.foldl_corresponding3(_, [_ | _], [_ | _], [], _, _) :-
+ error("list.foldl_corresponding3/6: mismatched list arguments").
+list.foldl_corresponding3(P, [ A | As ], [ B | Bs ], [ C | Cs], !Acc) :-
+ P(A, B, C, !Acc),
+ list.foldl_corresponding3(P, As, Bs, Cs, !Acc).
+
+list.foldl2_corresponding3(_, [], [], [], !Acc1, !Acc2).
+list.foldl2_corresponding3(_, [_ | _], [], [], _, _, _, _) :-
+ error("list.foldl2_corresponding3/8: mismatched list arguments").
+list.foldl2_corresponding3(_, [], [_ | _], [], _, _, _, _) :-
+ error("list.foldl2_corresponding3/8: mismatched list arguments").
+list.foldl2_corresponding3(_, [], [], [_ | _], _, _, _, _) :-
+ error("list.foldl2_corresponding3/8: mismatched list arguments").
+list.foldl2_corresponding3(_, [], [_ | _], [_ | _], _, _, _, _) :-
+ error("list.foldl2_corresponding3/8: mismatched list arguments").
+list.foldl2_corresponding3(_, [_ | _], [], [_ | _], _, _, _, _) :-
+ error("list.foldl2_corresponding3/8: mismatched list arguments").
+list.foldl2_corresponding3(_, [_ | _], [_ | _], [], _, _, _, _) :-
+ error("list.foldl2_corresponding3/8: mismatched list arguments").
+list.foldl2_corresponding3(P, [ A | As ], [ B | Bs ], [ C | Cs],
+ !Acc1, !Acc2) :-
+ P(A, B, C, !Acc1, !Acc2),
+ list.foldl2_corresponding3(P, As, Bs, Cs, !Acc1, !Acc2).
+
+list.foldl3_corresponding3(_, [], [], [], !Acc1, !Acc2, !Acc3).
+list.foldl3_corresponding3(_, [_ | _], [], [], _, _, _, _, _, _) :-
+ error("list.foldl3_corresponding3/10: mismatched list arguments").
+list.foldl3_corresponding3(_, [], [_ | _], [], _, _, _, _, _, _) :-
+ error("list.foldl3_corresponding3/10: mismatched list arguments").
+list.foldl3_corresponding3(_, [], [], [_ | _], _, _, _, _, _, _) :-
+ error("list.foldl3_corresponding3/10: mismatched list arguments").
+list.foldl3_corresponding3(_, [], [_ | _], [_ | _], _, _, _, _, _, _) :-
+ error("list.foldl3_corresponding3/10: mismatched list arguments").
+list.foldl3_corresponding3(_, [_ | _], [], [_ | _], _, _, _, _, _, _) :-
+ error("list.foldl3_corresponding3/10: mismatched list arguments").
+list.foldl3_corresponding3(_, [_ | _], [_ | _], [], _, _, _, _, _, _) :-
+ error("list.foldl3_corresponding3/10: mismatched list arguments").
+list.foldl3_corresponding3(P, [ A | As ], [ B | Bs ], [ C | Cs],
+ !Acc1, !Acc2, !Acc3) :-
+ P(A, B, C, !Acc1, !Acc2, !Acc3),
+ list.foldl3_corresponding3(P, As, Bs, Cs, !Acc1, !Acc2, !Acc3).
+
list.map_foldl(_, [], [], !A).
list.map_foldl(P, [H0 | T0], [H | T], !A) :-
P(H0, H, !A),
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list