[m-rev.] diff: list.det.drop

Zoltan Somogyi zs at csse.unimelb.edu.au
Wed Apr 28 10:48:28 AEST 2010


library/list.m:
	Add list.det_drop.

Zoltan.

cvs diff: Diffing library
Index: library/list.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.188
diff -u -b -r1.188 list.m
--- library/list.m	15 Apr 2010 02:56:01 -0000	1.188
+++ library/list.m	28 Apr 2010 00:43:50 -0000
@@ -236,10 +236,19 @@
     % list.drop(Len, List, End):
     %
     % `End' is the remainder of `List' after removing the first `Len' elements.
+    % Fails if `List' does not have at least `Len' elements.
     % See also: list.split_list.
     %
 :- pred list.drop(int::in, list(T)::in, list(T)::out) is semidet.
 
+    % list.det_drop(Len, List, End):
+    %
+    % `End' is the remainder of `List' after removing the first `Len' elements.
+    % Aborts if `List' does not have at least `Len' elements.
+    % See also: list.split_list.
+    %
+:- pred list.det_drop(int::in, list(T)::in, list(T)::out) is det.
+
     % list.insert(Elem, List0, List):
     %
     % `List' is the result of inserting `Elem' somewhere in `List0'.
@@ -1933,8 +1942,21 @@
 
 list.drop(N, As, Bs) :-
     ( N > 0 ->
-        As = [_ | Cs],
-        list.drop(N - 1, Cs, Bs)
+        As = [_ | TailAs],
+        list.drop(N - 1, TailAs, Bs)
+    ;
+        As = Bs
+    ).
+
+list.det_drop(N, As, Bs) :-
+    ( N > 0 ->
+        (
+            As = [_ | TailAs],
+            list.det_drop(N - 1, TailAs, Bs)
+        ;
+            As = [],
+            error("list.det_drop: not enough elements")
+        )
     ;
         As = Bs
     ).
--------------------------------------------------------------------------
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