[m-rev.] for review: format ints with thousand separators

Ian MacLarty maclarty at cs.mu.OZ.AU
Thu Feb 3 17:21:37 AEDT 2005


On Thu, Feb 03, 2005 at 05:02:44PM +1100, Julien Fischer wrote:
> 
> On Thu, 3 Feb 2005, Ian MacLarty wrote:
> 
> > For review by anyone.
> >
> > Estimated hours taken: 2
> > Branches: main
> >
> > Add predicates and functions to the string module to format integers with
> > thousand separators.
> >
> > library/string.m
> > 	Add predicate and function to convert an int to a string with
> s/Add predicate/Add a predicate/
> 

Fixed.

> > 	commas as thousand separators.  Add a predicate and function to
> > 	convert an int to any base with any string between any number of
> > 	digits.
> >
> > tests/general/string_test.exp
> > tests/general/string_test.m
> > 	Test the new functionality.
> >
> > Index: library/string.m
> > ===================================================================
> > RCS file: /home/mercury1/repository/mercury/library/string.m,v
> > retrieving revision 1.226
> > diff -u -r1.226 string.m
> > --- library/string.m	2 Feb 2005 04:28:49 -0000	1.226
> > +++ library/string.m	3 Feb 2005 05:50:13 -0000
> > @@ -119,6 +119,13 @@
> >  :- pred string__int_to_string(int, string).
> >  :- mode string__int_to_string(in, uo) is det.
> >
> > +	% Convert an integer to a string with commas as thousand seperators.
> > +	%
> > +:- func string__int_to_string_thousands(int) = string.
> > +:- mode string__int_to_string_thousands(in) = uo is det.
> > +:- pred string__int_to_string_thousands(int, string).
> > +:- mode string__int_to_string_thousands(in, uo) is det.
> > +
> Do we really need the predicate version?
> 

Yes, so the interface is consistent with string__int_to_string.  But if you
feel strongly I'll take the pred version out - I don't really care either way.

> >  	% string__int_to_base_string(Int, Base, String):
> >  	% Convert an integer to a string in a given Base (between 2 and 36).
> >  	%
> > @@ -127,6 +134,17 @@
> >  :- pred string__int_to_base_string(int, int, string).
> >  :- mode string__int_to_base_string(in, in, uo) is det.
> >
> > +	% string__int_to_base_string_group(Int, Base, GroupLength, Seperator,
> > +	%	String):
> > +	% Convert an integer to a string in a given Base (between 2 and 36)
> > +	% and insert Seperator between every GroupLength digits.  Useful
> > +	% for formatting numbers like "1,300,000".
> > +	%
> This comment should mention that it throws an exception if the Base is not
> between 2 and 36.
> 

Okay - I've also done the same for string__int_to_base_string.

> > +:- func string__int_to_base_string_group(int, int, int, string) = string.
> > +:- mode string__int_to_base_string_group(in, in, in, in) = uo is det.
> > +:- pred string__int_to_base_string_group(int, int, int, string, string).
> > +:- mode string__int_to_base_string_group(in, in, in, in, uo) is det.
> > +
> Likewise, are we really going to need a predicate verson of this?
> 

See above.

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