Open dimitrilw opened 4 months ago
I have a fork that adds:
isupper(String)
islower(String)
String.isupper()
String.islower()
It follows the same pattern as bgreni's isdigit
additions.
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: https://github.com/modularml/mojo/pull/3095
isdigit(Int8)
is actually isdigit(Char)
. Mojo used to use signed 8bit integer for char.
Not sure I follow.
The function signature at the time I originally wrote this was only one: fn isdigit(c: UInt8) -> Bool:
. Then bgreni added fn isdigit(c: String) -> Bool:
, which is a pass-through to the original function.
I was merely pointing out that one should think of the "numeric" overload as a function on char.
Tracking. ❤️
For ref, python 3 str.islower()
and str.isupper()
:
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