[m-rev.] For review: updates to string.m

Ralph Becket rafe at cs.mu.OZ.AU
Fri Jul 5 11:51:07 AEST 2002


Peter Ross, Wednesday,  3 July 2002:
> On Fri, Jun 28, 2002 at 11:59:01AM +1000, Ralph Becket wrote:
> > Some updates and additions to string.m.
> > 
> > Estimated hours taken: 4
> > Branches: main
> > 
> > library/string.m:
> > 	Added pred string__suffix/2.
> > 	Added funcs string__fold[lr]_substring/5.
> > 	Added preds string__fold[lr]_substring/6.
> > 	Added func string__foldr/3.
> > 	Added pred string__foldr/4.
> > 	Added func string__words/1.
> > 	Recoded string__prefix for efficiency.
> > 	Recoded string__sub_string_search_2 for efficiency.
> > 	Minor cosmetic changes to separator comments.
> > 
> > NEWS:
> > 	Mention the above changes.
> > 
> This looks fine, just one suggestion.
> Anywhere a string is out, I would change it to uo, since all strings are
> unique when they are created.

Here's the relative diff:

diff -u string.m string.m
--- string.m	3 Jul 2002 23:49:26 -0000
+++ string.m	4 Jul 2002 07:32:55 -0000
@@ -34,7 +34,7 @@
 
 :- pred string__append(string, string, string).
 :- mode string__append(in, in, in) is semidet.	% implied
-:- mode string__append(in, out, in) is semidet.
+:- mode string__append(in, uo, in) is semidet.
 :- mode string__append(in, in, uo) is det.
 :- mode string__append(out, out, in) is multi.
 %	Append two strings together.
@@ -70,27 +70,31 @@
 	% suffix of String.  Same as string__append(_, Suffix, String).
 
 :- func string__char_to_string(char) = string.
+:- mode string__char_to_string(in) = uo is det.
 :- pred string__char_to_string(char, string).
-:- mode string__char_to_string(in, out) is det.
+:- mode string__char_to_string(in, uo) is det.
 :- mode string__char_to_string(out, in) is semidet.
 %	string__char_to_string(Char, String).
 %		Converts a character (single-character atom) to a string
 %		or vice versa.
 
 :- func string__int_to_string(int) = string.
+:- mode string__int_to_string(in) = uo is det.
 :- pred string__int_to_string(int, string).
-:- mode string__int_to_string(in, out) is det.
+:- mode string__int_to_string(in, uo) is det.
 %	Convert an integer to a string.
 
 :- func string__int_to_base_string(int, int) = string.
+:- mode string__int_to_base_string(in, in) = uo is det.
 :- pred string__int_to_base_string(int, int, string).
-:- mode string__int_to_base_string(in, in, out) is det.
+:- mode string__int_to_base_string(in, in, uo) is det.
 %	string__int_to_base_string(Int, Base, String):
 %	Convert an integer to a string in a given Base (between 2 and 36).
 
 :- func string__float_to_string(float) = string.
+:- mode string__float_to_string(in) = uo is det.
 :- pred string__float_to_string(float, string).
-:- mode string__float_to_string(in, out) is det.
+:- mode string__float_to_string(in, uo) is det.
 %	Convert an float to a string.
 
 :- pred string__first_char(string, char, string).
@@ -111,28 +115,31 @@
 %		Use string__foldl or string__to_char_list instead.
 
 :- pred string__replace(string, string, string, string).
-:- mode string__replace(in, in, in, out) is semidet.
+:- mode string__replace(in, in, in, uo) is semidet.
 % string__replace(String0, Search, Replace, String):
 % 	string__replace replaces the first occurence of the second string in 
 % 	the first string with the third string to give the fourth string.
 % 	It fails if the second string does not occur in the first.
 
 :- func string__replace_all(string, string, string) = string.
+:- mode string__replace_all(in, in, in) = uo is det.
 :- pred string__replace_all(string, string, string, string).
-:- mode string__replace_all(in, in, in, out) is det.
+:- mode string__replace_all(in, in, in, uo) is det.
 % string__replace_all(String0, Search, Replace, String):
 % 	string__replace_all replaces any occurences of the second string in 
 % 	the first string with the third string to give the fourth string.
 
 :- func string__to_lower(string) = string.
+:- mode string__to_lower(in) = uo is det.
 :- pred string__to_lower(string, string).
-:- mode string__to_lower(in, out) is det.
+:- mode string__to_lower(in, uo) is det.
 :- mode string__to_lower(in, in) is semidet.		% implied
 %	Converts a string to lowercase.
 
 :- func string__to_upper(string) = string.
+:- mode string__to_upper(in) = uo is det.
 :- pred string__to_upper(string, string).
-:- mode string__to_upper(in, out) is det.
+:- mode string__to_upper(in, uo) is det.
 :- mode string__to_upper(in, in) is semidet.		% implied
 %	Converts a string to uppercase.
 
@@ -148,17 +155,19 @@
 
 :- func string__to_char_list(string) = list(char).
 :- pred string__to_char_list(string, list(char)).
-:- mode string__to_char_list(in, uo) is det.
+:- mode string__to_char_list(in, out) is det.
 :- mode string__to_char_list(uo, in) is det.
 
 :- func string__from_char_list(list(char)) = string.
+:- mode string__from_char_list(in) = uo is det.
 :- pred string__from_char_list(list(char), string).
-:- mode string__from_char_list(in, out) is det.
+:- mode string__from_char_list(in, uo) is det.
 :- mode string__from_char_list(out, in) is det.
 
 :- func string__from_rev_char_list(list(char)) = string.
+:- mode string__from_rev_char_list(in) = uo is det.
 :- pred string__from_rev_char_list(list(char), string).
-:- mode string__from_rev_char_list(in, out) is det.
+:- mode string__from_rev_char_list(in, uo) is det.
 %	Same as string__from_char_list, except that it reverses the order
 %	of the characters.
 
@@ -219,8 +228,9 @@
 %	as long as `Width', giving `String'.
 
 :- func string__duplicate_char(char, int) = string.
+:- mode string__duplicate_char(in, in) = uo is det.
 :- pred string__duplicate_char(char, int, string).
-:- mode string__duplicate_char(in, in, out) is det.
+:- mode string__duplicate_char(in, in, uo) is det.
 %	string__duplicate_char(Char, Count, String):
 %	construct a string consisting of `Count' occurrences of `Char'
 %	in sequence.
@@ -371,7 +381,7 @@
 %	string__words(String) = string__words(char__is_whitespace, String).
 
 :- pred string__split(string, int, string, string).
-:- mode string__split(in, in, out, out) is det.
+:- mode string__split(in, in, uo, uo) is det.
 %	string__split(String, Count, LeftSubstring, RightSubstring):
 %	`LeftSubstring' is the left-most `Count' characters of `String',
 %	and `RightSubstring' is the remainder of `String'.
@@ -379,22 +389,25 @@
 %	treated as if it were the nearest end-point of that range.)
 
 :- func string__left(string, int) = string.
+:- mode string__left(in, in) = uo is det.
 :- pred string__left(string, int, string).
-:- mode string__left(in, in, out) is det.
+:- mode string__left(in, in, uo) is det.
 %	string__left(String, Count, LeftSubstring):
 %	`LeftSubstring' is the left-most `Count' characters of `String'.
 %	(If `Count' is out of the range [0, length of `String'], it is
 %	treated as if it were the nearest end-point of that range.)
 
 :- func string__right(string, int) = string.
+:- mode string__right(in, in) = uo is det.
 :- pred string__right(string, int, string).
-:- mode string__right(in, in, out) is det.
+:- mode string__right(in, in, uo) is det.
 %	string__right(String, Count, RightSubstring):
 %	`RightSubstring' is the right-most `Count' characters of `String'.
 %	(If `Count' is out of the range [0, length of `String'], it is
 %	treated as if it were the nearest end-point of that range.)
 
 :- func string__substring(string, int, int) = string.
+:- mode string__substring(in, in, in) = uo is det.
 :- pred string__substring(string, int, int, string).
 :- mode string__substring(in, in, in, uo) is det.
 %	string__substring(String, Start, Count, Substring):
@@ -772,7 +785,7 @@
 	string__int_to_base_string_1(N, Base, Str).
 
 :- pred string__int_to_base_string_1(int, int, string).
-:- mode string__int_to_base_string_1(in, in, out) is det.
+:- mode string__int_to_base_string_1(in, in, uo) is det.
 
 string__int_to_base_string_1(N, Base, Str) :-
 	% Note that in order to handle MININT correctly,
@@ -790,7 +803,7 @@
 	).
 
 :- pred string__int_to_base_string_2(int, int, string).
-:- mode string__int_to_base_string_2(in, in, out) is det.
+:- mode string__int_to_base_string_2(in, in, uo) is det.
 
 string__int_to_base_string_2(NegN, Base, Str) :-
 	(
@@ -820,7 +833,7 @@
 */
 
 :- pragma promise_pure(string__to_char_list/2).
-:- pragma foreign_proc("C", string__to_char_list(Str::in, CharList::uo),
+:- pragma foreign_proc("C", string__to_char_list(Str::in, CharList::out),
 		[will_not_call_mercury, promise_pure, thread_safe], "{
 	MR_ConstString p = Str + strlen(Str);
 	CharList = MR_list_empty_msg(MR_PROC_LABEL);
@@ -902,7 +915,7 @@
         Str = tmp->ToString();
 }").
 
-string__to_char_list(Str::in, CharList::uo) :-
+string__to_char_list(Str::in, CharList::out) :-
 	string__to_char_list_2(Str, 0, CharList).
 string__to_char_list(Str::uo, CharList::in) :-
 	( CharList = [],
@@ -929,7 +942,7 @@
 % but the optimized implementation in C below is there for efficiency since
 % it improves the overall speed of parsing by about 7%.
 %
-:- pragma foreign_proc("C", string__from_rev_char_list(Chars::in, Str::out),
+:- pragma foreign_proc("C", string__from_rev_char_list(Chars::in, Str::uo),
 		[will_not_call_mercury, promise_pure, thread_safe], "
 {
 	MR_Word list_ptr;
@@ -1003,7 +1016,7 @@
         Str = tmp->ToString();
 }").
 
-string__from_rev_char_list(Chars::in, Str::out) :- 
+string__from_rev_char_list(Chars::in, Str::uo) :- 
 	Str = string__from_char_list(list__reverse(Chars)).
 
 :- pred string__int_list_to_char_list(list(int), list(char)).
@@ -1866,7 +1879,7 @@
 %-----------------------------------------------------------------------------%
 
 :- pragma foreign_proc("C",
-	string__float_to_string(FloatVal::in, FloatString::out),
+	string__float_to_string(FloatVal::in, FloatString::uo),
 		[will_not_call_mercury, promise_pure, thread_safe], "{
 	char buf[500];
 	sprintf(buf, ""%#.15g"", FloatVal);
@@ -2260,7 +2273,7 @@
 
 string__append(S1::in, S2::in, S3::in) :-
 	string__append_iii(S1, S2, S3).
-string__append(S1::in, S2::out, S3::in) :-
+string__append(S1::in, S2::uo, S3::in) :-
 	string__append_ioi(S1, S2, S3).
 string__append(S1::in, S2::in, S3::uo) :-
 	string__append_iio(S1, S2, S3).
@@ -2288,10 +2301,10 @@
 string__append_iii(X, Y, Z) :-
 	string__mercury_append(X, Y, Z).
 
-:- pred string__append_ioi(string::in, string::out, string::in) is semidet.
+:- pred string__append_ioi(string::in, string::uo, string::in) is semidet.
 
 :- pragma foreign_proc("C",
-	string__append_ioi(S1::in, S2::out,S3::in),
+	string__append_ioi(S1::in, S2::uo,S3::in),
 		[will_not_call_mercury, promise_pure, thread_safe], "{
 	size_t len_1, len_2, len_3;
 
@@ -2409,11 +2422,11 @@
 
 /*
 :- pred string__substring(string, int, int, string).
-:- mode string__substring(in, in, in, out) is det.
+:- mode string__substring(in, in, in, uo) is det.
 %	string__substring(String, Start, Count, Substring):
 */
 
-string__substring(Str::in, Start::in, Count::in, SubStr::out) :-
+string__substring(Str::in, Start::in, Count::in, SubStr::uo) :-
 	End = min(Start + Count, string__length(Str)),
 	SubStr = string__from_char_list(strchars(Start, End, Str)).
 
@@ -2478,7 +2491,7 @@
 
 /*
 :- pred string__split(string, int, string, string).
-:- mode string__split(in, in, out, out) is det.
+:- mode string__split(in, in, uo, uo) is det.
 %	string__split(String, Count, LeftSubstring, RightSubstring):
 %	`LeftSubstring' is the left-most `Count' characters of `String',
 %	and `RightSubstring' is the remainder of `String'.
@@ -2487,7 +2500,7 @@
 */
 
 :- pragma foreign_proc("C",
-	string__split(Str::in, Count::in, Left::out, Right::out),
+	string__split(Str::in, Count::in, Left::uo, Right::uo),
 		[will_not_call_mercury, promise_pure, thread_safe], "{
 	MR_Integer len;
 	MR_Word tmp;
@@ -2512,7 +2525,7 @@
 }").
 
 :- pragma foreign_proc("MC++",
-	string__split(Str::in, Count::in, Left::out, Right::out),
+	string__split(Str::in, Count::in, Left::uo, Right::uo),
 		[will_not_call_mercury, promise_pure, thread_safe], "{
 	MR_Integer len;
 	MR_Word tmp;
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list