[m-rev.] diff: add list.map_corresponding/4

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Jan 2 18:36:41 AEDT 2007


I require the following for an upcoming change.

Estimated hours taken: 0.1
Branches: main

Add a predicate version of list.map_corresponding/3.

library/list.m:
 	Add the new predicate.

NEWS:
 	Mention the addition.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.433
diff -u -r1.433 NEWS
--- NEWS	21 Dec 2006 03:00:48 -0000	1.433
+++ NEWS	2 Jan 2007 07:35:07 -0000
@@ -15,6 +15,9 @@

  Changes to the Mercury standard library:

+* We have added list.map_corresponding/4, a predicate version of 
+  list.map_corresponding/3.
+
  * We have added versions of list.foldl/4 and list.foldr/4 that have
    determinism multi.

Index: library/list.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.157
diff -u -r1.157 list.m
--- library/list.m	29 Nov 2006 06:42:39 -0000	1.157
+++ library/list.m	2 Jan 2007 07:26:01 -0000
@@ -590,6 +590,11 @@
      % An exception is raised if the list arguments differ in length.
      %
  :- func list.map_corresponding(func(A, B) = C, list(A), list(B)) = list(C).
+:- pred list.map_corresponding(pred(A, B, C), list(A), list(B), list(C)).
+:- mode list.map_corresponding(in(pred(in, in, out) is det), in, in, out)
+    is det.
+:- mode list.map_corresponding(in(pred(in, in, out) is semidet), in, in, out)
+    is semidet.

      % list.map_corresponding3(F, [A1, .. An], [B1, .. Bn], [C1, .. Cn]) =
      %   [F(A1, B1, C1), .., F(An, Bn, Cn)].
@@ -1804,6 +1809,15 @@
  list.map_corresponding(F, [A | As], [B | Bs]) =
      [F(A, B) | list.map_corresponding(F, As, Bs)].

+list.map_corresponding(_, [], [], []).
+list.map_corresponding(_, [], [_ | _], _) :-
+    error("list.map_corresponding/4: mismatched list arguments.").
+list.map_corresponding(_, [_ | _], [], _) :-
+    error("list.map_corresponding/4: mismatched list arguments.").
+list.map_corresponding(P, [A | As], [B | Bs], [C | Cs]) :-
+    P(A, B, C),
+    list.map_corresponding(P, As, Bs, Cs).
+
  list.map_corresponding3(F, As, Bs, Cs) =
      (
          As = [A | As0],

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