[m-rev.] for review: Modifications to string library implementation.

James Goddard goddardjames at yahoo.com
Thu Dec 18 17:31:15 AEDT 2003


Estimated hours taken: 1
Branches: main

Modified string library implementation.

library/string.m:
	Implemented the following procedures:
		char_list_remove_suffix/3
		char_list_remove_suffix_reversed/3

	Replaced all calls to list__remove_suffix/3 with the more
	specialized char_list_remove_suffix/3.
	This allows (for example) string__format to succeed in grade Java,
	even though Unification has not yet been implemented.

Index: string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.212
diff -u -d -r1.212 string.m
--- string.m	17 Dec 2003 00:46:20 -0000	1.212
+++ string.m	18 Dec 2003 06:12:40 -0000
@@ -785,7 +785,7 @@
 	string__to_char_list(A, LA),
 	string__to_char_list(B, LB),
 	string__to_char_list(C, LC),
-	list__remove_suffix(LA, LB, LC).
+	char_list_remove_suffix(LA, LB, LC).
 
 :- pragma promise_pure(string__prefix/2).
 
@@ -1449,7 +1449,7 @@
 		zero_or_more_occurences(digit),
 		=(Final),
 
-		{ list__remove_suffix(Init, Final, Width) },
+		{ char_list_remove_suffix(Init, Final, Width) },
 		{ PolyTypes = PolyTypes0 }
 	).
 
@@ -1476,7 +1476,7 @@
 		zero_or_more_occurences(digit),
 		=(Final)
 	->
-		{ list__remove_suffix(Init, Final, Prec) },
+		{ char_list_remove_suffix(Init, Final, Prec) },
 		{ PolyTypes = PolyTypes0 }
 	;
 			% When no number follows the '.' the precision
@@ -4055,6 +4055,28 @@
 	       )
 	  else N - (I + 1)
 	).
+
+%------------------------------------------------------------------------------%
+
+% char_list_remove_suffix/3 : We use this instead of the more general
+% list__remove_suffix so that string__format will not depend on unification.
+
+:- pred char_list_remove_suffix(list(char), list(char), list(char)).
+:- mode char_list_remove_suffix(in, in, out) is semidet.
+
+char_list_remove_suffix(List, Suffix, Prefix) :-
+	list__reverse(List, RevList),
+	list__reverse(Suffix, RevSuffix),
+	char_list_remove_suffix_reversed(RevList, RevSuffix, RevPrefix),
+	list__reverse(RevPrefix, Prefix).
+
+:- pred char_list_remove_suffix_reversed(list(char), list(char), list(char)).
+:- mode char_list_remove_suffix_reversed(in, in, out) is semidet.
+
+char_list_remove_suffix_reversed(ReversedList, [], ReversedList).
+
+char_list_remove_suffix_reversed([Char|RList], [Char|RSuffix], RPrefix) :-
+	char_list_remove_suffix_reversed(RList, RSuffix, RPrefix).
 
 %------------------------------------------------------------------------------%
 
--------------------------------------------------------------------------
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