-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] polymorphic string functions, like isdigit()
#2975
Comments
[External] [stdlib] Add `String.isdigit` Partially addresses #2975 - Added convenience `String` overload `isdigit` function - Add `isdigit` member to `String` that checks if all characters in a string are digits as python has Co-authored-by: bgreni <42788181+bgreni@users.noreply.github.com> Closes #3027 MODULAR_ORIG_COMMIT_REV_ID: ef774445f416c57af49885d289f53847a145418e
I have a fork that adds:
It follows the same pattern as bgreni's I also added tests for each of those additions, but want to ensure I pass all tests locally before submitting the PR. I could use a little hand-holding on "here's how you recompile Mojo locally from your local fork and ensure your system uses that mojo binary to run the test suite." |
PR to close this ticket when merged: #3095 |
|
Not sure I follow. The function signature at the time I originally wrote this was only one: |
I was merely pointing out that one should think of the "numeric" overload as a function on char. |
Tracking. ❤️ |
Review Mojo's priorities
What is your request?
Right now,
isdigit()
(found here) expects to receive a numeric value. I.e., the two noted lines fail:But if I pass
ord(<value>)
, then it works:In Python, the
str.isdigit()
method is called from the string itself. More, it does not require advance alteration of the input.Perhaps Mojo's
isdigit()
function should be polymorphic to take different inputs. For example, in Python, it can assess a full string of characters to confirm all are digits:I'm thinking that the Mojo function should perform similarly. Not necessarily as a String.method(), but rather just something that can take different inputs, to include something like
isdigit("1x3")
, which would evaluate asFalse
.If Modular peeps agree, then I will gladly work to make this real and make a PR.
Note, the same could be said about other functions:
islower
,isupper
, etc.Thoughts?
What is your motivation for this change?
Pythonic style to simplify onboarding Py-Peeps. Also, easier-to-read code; I believe
isdigit("x")
is more intuitive thanisdigit(ord("x"))
.Any other details?
No response
The text was updated successfully, but these errors were encountered: