[m-dev.] For review: add '..'/2 and series/3 to list.m

Ralph Becket rbeck at microsoft.com
Wed Sep 27 02:26:21 AEDT 2000


I've taken on board the discussion we had earlier this month and
made changes accordingly.

Estimated hours taken: 0.25

Added integer and generalised series functions.

library/list.m:
	Added '..'/2 - generates lists of ascending integers.
	Added list__series/3 - higher order function used to
		generate various kinds of series.

Index: list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.93
diff -u -r1.93 list.m
--- list.m	2000/09/08 15:53:15	1.93
+++ list.m	2000/09/26 15:06:52
@@ -505,11 +505,26 @@
 	in, in, out) is det.
 
 
%---------------------------------------------------------------------------
--%
+
+	% list__series(X, OK, Succ) = [X0, X1, ..., Xn]
+	% 	where Xk = Succ^k(X) and OK(Xk) and not OK(Succ^(n+1)(X)).
+	%
+:- func list__series(T, pred(T), func(T) = T) = list(T).
+:- mode list__series(in, pred(in) is semidet, func(in) = out is det) = out
+		is det.
+
+%
----------------------------------------------------------------------------
%
+
+	% Lo `..` Hi = [Lo, Lo + 1, ..., Hi]
+	%
+:- func int `..` int = list(int).
+
+%--------------------------------------------------------------------------
---%
 
%---------------------------------------------------------------------------
--%
 
 :- implementation.
 
-:- import_module bintree_set, require.
+:- import_module bintree_set, require, std_util.
 
 
%---------------------------------------------------------------------------
--%
 
@@ -1328,6 +1343,20 @@
 %
----------------------------------------------------------------------------
%
 
 L1 ++ L2 = list__append(L1, L2).
+
+%
----------------------------------------------------------------------------
%
+
+list__series(I, OK, Succ) =
+	( if OK(I) then
+		[I | list__series(Succ(I), OK, Succ)]
+	  else
+	  	[]
+	).
+
+%
----------------------------------------------------------------------------
%
+
+Lo `..` Hi =
+	list__series(Lo, ( pred(I::in) is semidet :- I =< Hi ), plus(1)).
 
 %
----------------------------------------------------------------------------
%
 %
----------------------------------------------------------------------------
%

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