[mercury-users] Strange behavior of string__to_int in Mercury
Gregory D. Weber
gdweber at indiana.edu
Thu Jul 1 01:16:23 AEST 2004
If S = "+" or "-", then
string__to_int(S, I)
succeeds with I = 0.
Shouldn't it succeed only if S has at least one digit?
(It does fail if S = "".)
Whether this is a bug or an annoying feature, it is easy to work around
with
S \= "+",
S \= "-",
string__to_int(S, I)
>From the library documentation:
:- func string__det_to_int(string) = int.
% Converts a signed base 10 string to an int;
% throws an exception if the string argument
% does not match the regexp [+-]?[0-9]+
:- pred string__to_int(string, int).
:- mode string__to_int(in, out) is semidet.
% Convert a string to an int. The string must contain only digits,
% optionally preceded by a plus or minus sign. If the string does
% not match this syntax, string__to_int fails.
If I read this correctly, then it is indeed a bug.
--
Gregory D. Weber
Associate Professor of Computer Science, Indiana University East
2325 Chester Boulevard, Richmond, Indiana 47374-1289, U.S.A.
Telephone: (765) 973-8420 World-Wide Web http://mypage.iu.edu/~gdweber/
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list