[m-rev.] diff: add char.det_digit_to_int/1

Julien Fischer jfischer at opturion.com
Fri Sep 5 11:22:39 AEST 2014


Add char.det_digit_to_int/1 to the library.

library/char.m:
 	As above.

NEWS:
 	Announce the addition.

Julien.

diff --git a/NEWS b/NEWS
index 6c04eed..62f3974 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,8 @@ Changes to the Mercury standard library:

  * Procedures in the store module no longer acquire the global lock.

+* We have added the function det_digit_to_int/1 to the char module.
+
  Changes to the Mercury compiler:

  * We have fixed a long-standing bug causing crashes in deep profiling
diff --git a/library/char.m b/library/char.m
index be30155..40edc1c 100644
--- a/library/char.m
+++ b/library/char.m
@@ -164,6 +164,10 @@
      %
  :- pred char.digit_to_int(char::in, int::out) is semidet.

+    % As above, but calls error/1 instead of failing.
+    %
+:- func char.det_digit_to_int(char) = int.
+
      % char.int_to_uppercase_digit(Int, DigitChar):
      %
      % True iff `Int' is an integer in the range 0-35 and
@@ -490,6 +494,13 @@ char.digit_to_int(Digit, Int) :-
          char.int_to_digit(Int, Digit)
      ).

+char.det_digit_to_int(Digit) = Int :-
+    ( digit_to_int(Digit, Int0) ->
+        Int = Int0
+    ;
+        error("char.digit_to_int failed")
+    ).
+
  %-----------------------------------------------------------------------------%

  char.lower_upper('a', 'A').



More information about the reviews mailing list