[m-rev.] diff: add list.all_{true,false}_corresponding/3

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Jun 27 22:32:40 AEST 2012


Branches: main

library/list.m:
 	Add the predictes list.all_{true,false}_corresponding/3.

NEWS:
 	Announce the addition.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.614
diff -u -r1.614 NEWS
--- NEWS	19 Jun 2012 07:21:23 -0000	1.614
+++ NEWS	27 Jun 2012 12:21:35 -0000
@@ -35,6 +35,9 @@
  * The lexer module returns base 10 integer literals in the string
    representation, if the integer is too large for an `int'.

+* We have add the following new predicates to the list module:
+  list.all_true_corresponding/3 and list.all_false_corresponding/3.
+
  Changes to the Mercury debugger:

  * We have added new capabilities to the "level", "retry" and "finish" mdb
Index: library/list.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.209
diff -u -r1.209 list.m
--- library/list.m	13 Jun 2012 15:45:47 -0000	1.209
+++ library/list.m	27 Jun 2012 12:23:17 -0000
@@ -1434,6 +1434,16 @@
  :- pred list.all_true(pred(X)::in(pred(in) is semidet), list(X)::in)
      is semidet.

+    % list.all_true_corresponding(Pred, ListA, ListB):
+    % Succeeds if Pred succeeds for every corresponding pair of elements from
+    % ListA and ListB.  Fails if Pred fails for any pair of corresponding
+    % elements.
+    %
+    % An exception is raised if the list arguments differ in length.
+    %
+:- pred list.all_true_corresponding(pred(X, Y)::in(pred(in, in) is semidet),
+    list(X)::in, list(Y)::in) is semidet.
+
      % list.all_false(Pred, List) takes a closure with one input argument.
      % If Pred fails for every member of List, all_false succeeds.
      % If Pred succeeds for any member of List, all_false fails.
@@ -1441,6 +1451,16 @@
  :- pred list.all_false(pred(X)::in(pred(in) is semidet), list(X)::in)
      is semidet.

+    % list.all_false_corresponding(Pred, ListA, ListB):
+    % Succeeds if Pred fails for every corresponding pair of elements from
+    % ListA and ListB.  Fails if Pred succeeds for any pair of corresponding
+    % elements.
+    %
+    % An exception is raised if the list arguments differ in length.
+    %
+:- pred list.all_false_corresponding(pred(X, Y)::in(pred(in, in) is semidet),
+    list(X)::in, list(Y)::in) is semidet.
+
      % list.find_first_match(Pred, List, FirstMatch) takes a closure with one
      % input argument. It returns the element X of the list (if any) for which
      % Pred(X) is true.
@@ -2728,11 +2748,29 @@
      P(X),
      list.all_true(P, Xs).

+list.all_true_corresponding(_P, [], []).
+list.all_true_corresponding(_P, [], [_ | _]) :-
+    unexpected($module, $pred, "mismatched list lengths").
+list.all_true_corresponding(_P, [_ | _], []) :-
+    unexpected($module, $pred, "mismatched list lengths").
+list.all_true_corresponding(P, [X | Xs], [Y | Ys]) :-
+    P(X, Y),
+    list.all_true_corresponding(P, Xs, Ys).
+
  list.all_false(_P, []).
  list.all_false(P, [X | Xs]) :-
      not P(X),
      list.all_false(P, Xs).

+list.all_false_corresponding(_P, [], []).
+list.all_false_corresponding(_P, [], [_ | _]) :-
+    unexpected($module, $pred, "mismatched list lengths").
+list.all_false_corresponding(_P, [_ | _], []) :-
+    unexpected($module, $pred, "mismatched list lengths").
+list.all_false_corresponding(P, [X | Xs], [Y | Ys]) :-
+    not P(X, Y),
+    list.all_false_corresponding(P, Xs, Ys).
+
  list.find_first_match(P, [H | T], FirstMatch) :-
      ( P(H) ->
          FirstMatch = H

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