[m-dev.] For review: minor additions to list.m and string.m
Ralph Becket
rbeck at microsoft.com
Fri Sep 8 03:02:57 AEDT 2000
Estimated hours taken: 0.25
Small additions to list and string.
library/list.m:
Added func ++/2 as a synonym for list__append/2.
Added func '..'/1 to generate ascending/descending integer range
lists.
library/string.m:
Added func ++/2 as a synonym for string__append/2.
? 2000-09-07.diff
? 2000-09-07.log
Index: list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.92
diff -u -r1.92 list.m
--- list.m 2000/07/19 03:41:54 1.92
+++ list.m 2000/09/07 15:49:43
@@ -86,7 +86,11 @@
% to a rewrite rule.
:- promise all [L,H,T] ( append([H], T, L) <=> L = [H|T] ).
+ % L1 ++ L2 = L :- list__append(L1, L2, L).
+ %
+:- func list(T) ++ list(T) = list(T).
+
% list__remove_suffix(List, Suffix, Prefix):
% The same as list__append(Prefix, Suffix, List) except that
% this is semidet whereas list__append(out, in, in) is nondet.
@@ -500,6 +504,13 @@
:- mode list__merge_and_remove_dups(pred(in, in, out) is det,
in, in, out) is det.
+%
----------------------------------------------------------------------------
%
+
+ % N `..` M = [N, N + 1, N + 2, ..., M] if N =< M
+ % = [N, N - 1, N - 2, ..., M] if M < N
+ %
+:- func int `..` int = list(int).
+
%---------------------------------------------------------------------------
--%
%---------------------------------------------------------------------------
--%
@@ -1321,3 +1332,23 @@
P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
list__merge_and_remove_dups(P, Xs, Ys, Zs).
+%
----------------------------------------------------------------------------
%
+
+L1 ++ L2 = list__append(L1, L2).
+
+%
----------------------------------------------------------------------------
%
+
+N `..` M = int_series(N, M, [], ( if N =< M then plus(-1) else plus(1) )).
+
+%
----------------------------------------------------------------------------
%
+
+ % Construct the series [F^n(M), F^(n-1)(M), ..., F(M), M]
+ % where F^n(M) = N
+ %
+:- func int_series(int, int, list(int), func(int) = int) = list(int).
+
+int_series(N, M, Acc, F) =
+ ( if N = M then [N | Acc] else int_series(N, F(M), [M | Acc], F) ).
+
+%
----------------------------------------------------------------------------
%
+%
----------------------------------------------------------------------------
%
Index: string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.127
diff -u -r1.127 string.m
--- string.m 2000/08/17 09:58:05 1.127
+++ string.m 2000/09/07 15:49:48
@@ -34,6 +34,11 @@
% that it is semidet. Use string__remove_suffix instead.
% :- mode string__append(out, in, in) is semidet.
+:- func string ++ string = string.
+% S1 ++ S2 = S :- string__append(S1, S2, S).
+%
+% Nicer syntax.
+
:- pred string__remove_suffix(string, string, string).
:- mode string__remove_suffix(in, in, out) is semidet.
% string__remove_suffix(String, Suffix, Prefix):
@@ -1874,6 +1879,10 @@
else
preceding_boundary(SepP, String, I - 1)
).
+
+%
----------------------------------------------------------------------------
%
+
+S1 ++ S2 = string__append(S1, S2).
%
----------------------------------------------------------------------------
%
%
----------------------------------------------------------------------------
%
--
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