[m-rev.] diff: add list.foldl_corresponding function to stdlib

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Feb 7 00:50:25 AEDT 2012


Branches: main, 11.07

Add a function version of list.foldl_corresponding to the standard library.

library/list.m:
 	Add the function list.foldl_corresponding/4.

NEWS:
 	Announce the addition.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.601
diff -u -r1.601 NEWS
--- NEWS	24 Jan 2012 05:23:06 -0000	1.601
+++ NEWS	6 Feb 2012 13:44:03 -0000
@@ -24,6 +24,8 @@
  * We have added the predicates set.is_singleton/2, set_bbbtree.is_singleton/2,
    set_ctree234.is_singleton/2 and set_unordlist.is_singleton/2.

+* We have added the function list.foldl_corresponding/4.
+

  NEWS for Mercury 11.07
  ----------------------
Index: library/list.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.205
diff -u -r1.205 list.m
--- library/list.m	3 Jan 2012 11:04:48 -0000	1.205
+++ library/list.m	6 Feb 2012 13:45:51 -0000
@@ -942,8 +942,8 @@
  :- mode list.foldl6(pred(in, in, out, in, out, in, out, in, out, in, out,
      in, out) is nondet,
      in, in, out, in, out, in, out, in, out, in, out, in, out) is nondet.
-
-    % list.foldl_corresponding(F, As, Bs, !Acc):
+ 
+    % list.foldl_corresponding(P, As, Bs, !Acc):
      % Does the same job as list.foldl, but works on two lists in
      % parallel.  An exception is raised if the list arguments differ
      % in length.
@@ -970,6 +970,8 @@
  :- mode list.foldl_corresponding(pred(in, in, di, uo) is cc_multi,
      in, in, di, uo) is cc_multi.

+:- func list.foldl_corresponding(func(A, B, C) = C, list(A), list(B), C) = C.
+
      % list.foldl2_corresponding(F, As, Bs, !Acc1, !Acc2):
      % Does the same job as list.foldl_corresponding, but has two
      % accumulators.
@@ -2519,6 +2521,15 @@
      P(A, B, !Acc),
      list.foldl_corresponding(P, As, Bs, !Acc).

+list.foldl_corresponding(_, [], [], Acc) = Acc.
+list.foldl_corresponding(_, [], [_ | _], _) = _ :-
+    error("list.foldl_corresponding/4: mismatched list arguments").
+list.foldl_corresponding(_, [_ | _], [], _) = _ :-
+    error("list.foldl_corresponding/4: mismatched list arguments").
+list.foldl_corresponding(F, [A | As], [B | Bs], !.Acc) = !:Acc :-
+    !:Acc = F(A, B, !.Acc),
+    !:Acc = list.foldl_corresponding(F, As, Bs, !.Acc).
+
  list.foldl2_corresponding(_, [], [], !Acc1, !Acc2).
  list.foldl2_corresponding(_, [], [_ | _], _, _, _, _) :-
      error("list.foldl2_corresponding/7: mismatched list arguments").

--------------------------------------------------------------------------
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