[m-rev.] for review: Improve `integer' module interface.
Julien Fischer
jfischer at opturion.com
Sat Feb 14 23:21:03 AEDT 2015
Hi Peter,
On Fri, 13 Feb 2015, Peter Wang wrote:
> Add integer.to_int/2 which fails instead of throwing an exception if the
> value cannot be represented as an `int'.
>
> Deprecate semidet functions:
> from_string/1, from_base_string/2, int/1
>
> Add semidet predicates to replace them:
> from_string/2, from_base_string/3, det_to_int/1
det_to_int/1 is not a predicate, nor is it semidet.
>
> library/integer.m:
> As above.
>
> library/string.format.m:
> Conform to changes.
>
> NEWS:
> Announce changes.
>
> * The following predicates and functions have been added to the require module:
>
> - error/2
> diff --git a/library/integer.m b/library/integer.m
> index 4312c33..eb962be 100644
> --- a/library/integer.m
> +++ b/library/integer.m
....
> @@ -1038,17 +1055,21 @@ float_list(_, Accum, []) = Accum.
> float_list(FBase, Accum, [H | T]) =
> float_list(FBase, Accum * FBase + float.float(H), T).
>
> -integer.int(Integer) = Int :-
> - (
> - Integer >= integer(int.min_int),
> - Integer =< integer(int.max_int)
> - ->
> - Integer = i(_Sign, Digits),
> - Int = int_list(Digits, 0)
> +integer.to_int(Integer, Int) :-
> + Integer >= integer(int.min_int),
> + Integer =< integer(int.max_int),
> + Integer = i(_Sign, Digits),
> + Int = int_list(Digits, 0).
> +
> +integer.det_to_int(Integer) = Int :-
> + ( integer.to_int(Integer, IntPrime) ->
> + Int = IntPrime
> ;
> error("integer.int: domain error (conversion would overflow)")
> ).
s/integer\.int/integer\.det_to_int/ in the error message there.
The change looks fine otherwise.
Cheers,
Julien.
More information about the reviews
mailing list