[m-dev.] is_digit/1 and digit_to_int/2
Peter Wang
novalazy at gmail.com
Fri Sep 5 16:43:26 AEST 2014
On Fri, 5 Sep 2014 16:13:59 +1000 (EST), Julien Fischer <jfischer at opturion.com> wrote:
>
> On Fri, 5 Sep 2014, Peter Wang wrote:
>
> > On Fri, 5 Sep 2014 15:12:49 +1000 (EST), Julien Fischer <jfischer at opturion.com> wrote:
> >>
> >> Hi,
> >>
> >> I think it is potentially confusing that char.is_digit/1 and
> >> char.digit_to_int/2 are true for different inputs. The former only
> >> succeeds for 0-9, while the latter succeeds for 0-9a-zA-Z.
> >>
> >> At the very least I think we should have is_decimal_digit/1 and
> >> decimal_digit_to_int/2 that are both only true for 0-9.
> >
> > Oh, I have misused char.digit_to_int at least once. There is a buggy
> > use in the compiler as well (rev_find_number_suffix).
>
> That should be fixed.
>
> > Is it too late to deprecate char.digit_to_int?i
>
> I think it should be deprecated, if only to alert users to the fact that
> existing code that uses it may be broken.
Good.
> > And perhaps
> > char.int_to_uppercase_digit, char.int_to_digit, char.det_int_to_digit?
> >
> > The replacements could take an explicit base from 2 to 36.
>
> Ok, so how about we deprecate those and add:
>
> :- pred is_decimal_digit/1 (synonym for is_digit/1)
> :- pred decimal_digit_to_int/2
> :- func det_decimal_digit_to_int/1
Ok.
> :- pred int_to_base_digit/3
> :- func det_int_to_base_digit/3
The conventional order would have the base first, but
`int_to_base_digit' suggests that the base is second like
string.int_to_base_string.
What about:
% base_int_to_digit(Base, Int, Char):
%
% True iff `Char' is a single decimal digit (0-9) or uppercase
% letter (A-Z) representing the value `Int' in the given base.
% An exception is thrown if Base is not between 2 and 36.
%
:- pred base_int_to_digit(int, int, char).
:- mode base_int_to_digit(in, in, out) is semidet.
:- mode base_int_to_digit(in, out, in) is semidet.
Peter
More information about the developers
mailing list