I use String.to_int, and some time i get errors, for example when the string is not a representation of an int. I would like to catch these errors, or test parameter before to use the function. Some ideas ?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Hmm, one could argue that it would have been better if
String.to_intfrom the stdlib returned an optional integer (noneindicating an error).However, in Opa most parsing is done using parsers*. For instance to get the aforementioned function you could write:
or, if you want to be less verbose the equivalent:
or if it’s part of the more complex parsing you would just use the
Rule.integerparser there.(*) I guess this section of the manual could use some extensions…