[m-rev.] for review: add string.det_to_float/1 to standard library

Julien Fischer juliensf at cs.mu.OZ.AU
Sun Jan 9 00:16:06 AEDT 2005


Estimated hours taken: 0.2
Branches: main

library/string.m:
	Add a function, string.det_to_float/1.

	Fix a few typos.

NEWS:
	Mention the new function.

Julien.

Workspace:/home/earth/juliensf/ws54
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.223
diff -u -r1.223 string.m
--- library/string.m	20 Dec 2004 14:22:53 -0000	1.223
+++ library/string.m	8 Jan 2005 12:29:19 -0000
@@ -147,14 +147,14 @@
 :- mode string__first_char(uo, in, in) is det.

 	% string__replace(String0, Search, Replace, String):
-	% string__replace replaces the first occurence of Search in String0
+	% string__replace replaces the first occurrence of Search in String0
 	% with Replace to give String. It fails if Search does not occur
 	% in String0.
 :- pred string__replace(string, string, string, string).
 :- mode string__replace(in, in, in, uo) is semidet.

 	% string__replace_all(String0, Search, Replace, String):
-	% string__replace_all replaces any occurences of Search in
+	% string__replace_all replaces any occurrences of Search in
 	% String0 with Replace to give String.
 :- func string__replace_all(string, string, string) = string.
 :- mode string__replace_all(in, in, in) = uo is det.
@@ -215,7 +215,7 @@
 	% Convert a string in the specified base (2-36) to an int. The
 	% string must contain one or more digits in the specified base,
 	% optionally preceded by a plus or minus sign. For bases > 10,
-	% digits 10 to 35 are repesented by the letters A-Z or a-z. If
+	% digits 10 to 35 are represented by the letters A-Z or a-z. If
 	% the string does not match this syntax, the predicate fails.
 :- pred string__base_string_to_int(int::in, string::in, int::out) is semidet.

@@ -224,7 +224,12 @@
 	% by a non-empty string of base N digits.
 :- func string__det_base_string_to_int(int, string) = int.

-	% Convert a string to an float. If the string is not a syntactically
+	% Convert a string to a float.  Throws an exception if the string
+	% is not a syntactically correct float literal.
+	%
+:- func string__det_to_float(string) = float.
+
+	% Convert a string to a float. If the string is not a syntactically
 	% correct float literal, string__to_float fails.
 :- pred string__to_float(string::in, float::out) is semidet.

@@ -2897,6 +2902,12 @@
 "
 	FloatString = java.lang.Double.toString(FloatVal);
 ").
+
+string__det_to_float(FloatString) =
+	( if	string__to_float(FloatString, FloatVal)
+	  then	FloatVal
+	  else	func_error("string.det_to_float/1 - conversion failed.")
+	).

 :- pragma export(string__to_float(in, out), "ML_string_to_float").
 :- pragma foreign_proc("C",
Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.358
diff -u -r1.358 NEWS
--- NEWS	7 Jan 2005 06:10:31 -0000	1.358
+++ NEWS	8 Jan 2005 12:20:19 -0000
@@ -223,7 +223,8 @@

 * Several new functions have been added to the string module, namely
   elem/2, unsafe_elem/2, chomp/1, lstrip/1, lstrip/2, rstrip/1, rstrip/2,
-  strip/1, prefix_length/2, suffix_length/2, string/1, string/2 and string/4.
+  strip/1, prefix_length/2, suffix_length/2, string/1, string/2, string/4
+  and string.det_to_float/1.

 * We've added some new predicates, list__map2_foldl, list__map_foldl3,
   and list__foldl4 to list.m.

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