[m-dev.] For review: minor additions to array.m, std_util.m, string.m
Ralph Becket
rbeck at microsoft.com
Wed Apr 12 02:53:39 AEST 2000
Hopefully nobody will object...
Ralph
Estimated hours taken: 3
[Mainly down to getting reaquainted with remote CVS]
Miscellaneous small library improvements.
library/string.m
Added string__length/1 function.
library/array.m
Added `in' mode versions of array.m functions with `array_ui' modes.
This is handy for immutable arrays.
library/std_util.m
Added func `id/1' that computes the identity function.
Added pred `isnt/2' to invert sense of semidet preds for higher
order programming. For example, where one might write
Odds = list__filter(odd, Xs)
one could now also write
Evens = list__filter(isnt(odd), Xs)
Index: string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.120
diff -u -u -r1.120 string.m
--- string.m 2000/03/20 09:01:49 1.120
+++ string.m 2000/04/11 16:45:43
@@ -1988,6 +1988,8 @@
:- interface.
+:- func string__length(string) = int.
+
:- func string__append(string, string) = string.
:- func string__char_to_string(char) = string.
@@ -2044,6 +2046,9 @@
%
----------------------------------------------------------------------------
%
:- implementation.
+
+string__length(S) = L :-
+ string__length(S, L).
string__append(S1, S2) = S3 :-
string__append(S1, S2, S3).
Index: std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.187
diff -u -u -r1.187 std_util.m
--- std_util.m 2000/04/02 06:37:15 1.187
+++ std_util.m 2000/04/11 16:46:01
@@ -225,6 +225,17 @@
%---------------------------------------------------------------------------
--%
+ % isnt(Pred, X) <=> not Pred(X)
+ %
+ % This is useful in higher order programming, e.g.
+ % Odds = list__filter(odd, Xs)
+ % Evens = list__filter(isnt(odd), Xs)
+ %
+:- pred isnt(pred(T), T).
+:- mode isnt(pred(in) is semidet, in) is semidet.
+
+%--------------------------------------------------------------------------
---%
+
% `semidet_succeed' is exactly the same as `true', except that
% the compiler thinks that it is semi-deterministic. You can
% use calls to `semidet_succeed' to suppress warnings about
@@ -3154,6 +3165,10 @@
% Function exponentiation.
:- func pow(func(T) = T, int, T) = T.
+ % The identity function.
+ %
+:- func id(T) = T.
+
%
----------------------------------------------------------------------------
%
%
----------------------------------------------------------------------------
%
@@ -3173,3 +3188,8 @@
pow(F, N, X) =
( if N = 0 then X else pow(F, N - 1, F(X)) ).
+
+isnt(P, X) :-
+ not P(X).
+
+id(X) = X.
Index: array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.68
diff -u -u -r1.68 array.m
--- array.m 2000/03/10 01:21:29 1.68
+++ array.m 2000/04/11 16:46:07
@@ -768,15 +768,19 @@
:- func array__min(array(_T)) = int.
:- mode array__min(array_ui) = out is det.
+:- mode array__min(in) = out is det.
:- func array__max(array(_T)) = int.
:- mode array__max(array_ui) = out is det.
+:- mode array__max(in) = out is det.
:- func array__size(array(_T)) = int.
:- mode array__size(array_ui) = out is det.
+:- mode array__size(in) = out is det.
:- func array__lookup(array(T), int) = T.
:- mode array__lookup(array_ui, in) = out is det.
+:- mode array__lookup(in, in) = out is det.
:- func array__set(array(T), int, T) = array(T).
:- mode array__set(array_di, in, in) = array_uo is det.
@@ -787,6 +791,7 @@
:- func array__copy(array(T)) = array(T).
:- mode array__copy(array_ui) = array_uo is det.
+:- mode array__copy(in) = array_uo is det.
:- func array__resize(array(T), int, T) = array(T).
:- mode array__resize(array_di, in, in) = array_uo is det.
@@ -799,12 +804,15 @@
:- func array__to_list(array(T)) = list(T).
:- mode array__to_list(array_ui) = out is det.
+:- mode array__to_list(in) = out is det.
:- func array__fetch_items(array(T), int, int) = list(T).
:- mode array__fetch_items(array_ui, in, in) = out is det.
+:- mode array__fetch_items(in, in, in) = out is det.
:- func array__bsearch(array(T), T, func(T,T) = comparison_result) =
maybe(int).
:- mode array__bsearch(array_ui, in, func(in,in) = out is det) = out is
det.
+:- mode array__bsearch(in, in, func(in,in) = out is det) = out is det.
:- func array__map(func(T1) = T2, array(T1)) = array(T2).
:- mode array__map(func(in) = out is det, array_di) = array_uo is det.
--
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