[m-dev.] For review: small addition to list.m

Ralph Becket rbeck at microsoft.com
Thu Sep 28 18:45:57 AEDT 2000


This is an idiom I often find useful...

Estimated hours taken: 0.1

Added a pred that decomposes a non-empty list into its head
and tail (an error is raised if the input list is empty).

library/list.m:
	Added pred list__det_head_tail/3.

Index: list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.94
diff -u -r1.94 list.m
--- list.m	2000/09/27 08:01:12	1.94
+++ list.m	2000/09/27 14:43:05
@@ -524,6 +524,14 @@
 	%
 :- func int `..` int = list(int).
 
+%
----------------------------------------------------------------------------
%
+
+	% list__det_head_tail(List, Head, Tail)
+	% 	<=> ( list__det_head(List, Head), list__det_tail(List, Tail)
).
+	%
+:- pred list__det_head_tail(list(T), T, list(T)).
+:- mode list__det_head_tail(in, out, out) is det.
+
 
%---------------------------------------------------------------------------
--%
 
%---------------------------------------------------------------------------
--%
 
@@ -1362,6 +1370,13 @@
 
 Lo `..` Hi =
 	list__series(Lo, ( pred(I::in) is semidet :- I =< Hi ), plus(1)).
+
+%
----------------------------------------------------------------------------
%
+
+list__det_head_tail([], _, _) :-
+	error("list__det_head_tail/3: empty list argument").
+
+list__det_head_tail([H | T], H, T).
 
 %
----------------------------------------------------------------------------
%
 %
----------------------------------------------------------------------------
%

--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list