[v2] IsDigit to return True for positive Integers
Posted: 07 Jan 2023, 15:35
This is either a wish to change IsDigit behavior, or a wish for documentation improvement:
Currently the docs for IsDigit says that it returns "True if Value is a positive integer, [...]", but also that "Value must be a string, otherwise a TypeError is thrown.". IsDigit(5) throws an error, so currently positive pure numeric values are not allowed.
In the source for script2.cpp it's commented that pure numeric values shouldn't be allowed for funcs other than IsNumber, IsInteger, IsFloat because the results would be unintuitive, but in my opinion it would be intuitive for IsDigit to be True for pure numeric values of >=0.
Edit: On further thought I wouldn't be opposed for IsAlnum to have the same behavior. As an user I would like for these functions to answer the question I'm asking as easily and clearly as possible, and not be fussy about the types of variables passed to the function. The question with IsDigit is that "does this value consist on only digits from 0-9?", and the answer should be for IsDigit("5") and IsDigit(5) both to return True since both consist of digits from 0-9, and I don't care whether one is actually a string or pure numeric value behind the scenes. If I did care about the type, I would use IsInteger.
With IsAlnum the issue seems a bit more complex, since the "alpha" part implies we might want to be dealing with strings instead of pure numeric values. But still, the question is whether the argument contains only numbers and letters, and the answer for IsAlnum(5) should still be True since a non-negative integer contains only numbers.
Currently the docs for IsDigit says that it returns "True if Value is a positive integer, [...]", but also that "Value must be a string, otherwise a TypeError is thrown.". IsDigit(5) throws an error, so currently positive pure numeric values are not allowed.
In the source for script2.cpp it's commented that pure numeric values shouldn't be allowed for funcs other than IsNumber, IsInteger, IsFloat because the results would be unintuitive, but in my opinion it would be intuitive for IsDigit to be True for pure numeric values of >=0.
Edit: On further thought I wouldn't be opposed for IsAlnum to have the same behavior. As an user I would like for these functions to answer the question I'm asking as easily and clearly as possible, and not be fussy about the types of variables passed to the function. The question with IsDigit is that "does this value consist on only digits from 0-9?", and the answer should be for IsDigit("5") and IsDigit(5) both to return True since both consist of digits from 0-9, and I don't care whether one is actually a string or pure numeric value behind the scenes. If I did care about the type, I would use IsInteger.
With IsAlnum the issue seems a bit more complex, since the "alpha" part implies we might want to be dealing with strings instead of pure numeric values. But still, the question is whether the argument contains only numbers and letters, and the answer for IsAlnum(5) should still be True since a non-negative integer contains only numbers.