[m-dev.] is_digit/1 and digit_to_int/2

Julien Fischer jfischer at opturion.com
Fri Sep 5 16:13:59 AEST 2014


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.

> 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

   :- pred int_to_base_digit/3
   :- func det_int_to_base_digit/3

(There is no int_to_uppercase_digit as far as I can see, it's just
mentioned in the documentation for int_to_digit.)

Cheers,
Julien.



More information about the developers mailing list