-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Keywords for string, deprecate bin, oct, dec, hex, base #25717
Conversation
Based on the advice here: #25188 (comment) |
HISTORY.md
Outdated
@@ -417,7 +417,7 @@ Library improvements | |||
respectively perform predicate function negation and function composition. For example, | |||
`map(!iszero, (0, 1))` is now equivalent to `map(x -> !iszero(x), (0, 1))` and | |||
`map(uppercase ∘ hex, 250:255)` is now equivalent to | |||
`map(x -> uppercase(hex(x)), 250:255)` ([#17155]). | |||
`map(x -> uppercase(base(16, x)), 250:255)` ([#17155]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file should be left alone --- no need to try to rewrite history :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't tell Howard Zinn
base/libgit2/oid.jl
Outdated
assert_sixteen(b) | ||
join([base(b,i,2) for i in id.val]) | ||
end | ||
function Base.base(b, id::GitShortHash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure these methods should exist (same applies to the hex
methods, which I was unaware of). Converting a GitHash to a string does the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's just deprecate hex
in favour of string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also be removed from exports.jl
base/intfuncs.jl
Outdated
``` | ||
""" | ||
dec | ||
base(b::Integer, n::Char; pad::Integer = 1) = base(b, UInt32(n); pad = pad) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be removed (i.e. deprecated). Might as well require explicitly calling UInt32(c)
.
base/libgit2/oid.jl
Outdated
""" | ||
raw(id::GitHash) -> Vector{UInt8} | ||
|
||
Obtain the raw bytes of the [`GitHash`](@ref) as a vector of length $OID_RAWSZ. | ||
""" | ||
raw(id::GitHash) = collect(id.val) | ||
|
||
Base.string(id::AbstractGitHash) = hex(id) | ||
Base.string(id::AbstractGitHash) = base(16, id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a base(::Int, ::AbstractGitHash)
method defined somewhere?
What I meant in my previous comment was to define:
Base.string(id::GitHash) = join([base(i,2,pad=2) for i in id.val])
Base.string(id::GitShortHash) = string(id.hash)[1:id.len]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh got it I thought you meant these were already defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should actually be a method of print
, then you also get string
for free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually define string
when it's actually easier to compute the String representation than to print it. This is quite rare, but if it can be implemented by calling base
, this would be one of those cases.
Would it make sense to also provide some option to pad to the full width of the type (say |
Let's avoid adding new features for now. |
Deprecating |
That sounds better to me, especially because string(x::Union{Int8,Int16,Int32,Int64,Int128}) = base(10, x) |
I like that, especially since |
Ok, let's go with that then! Delete all the verbs!! |
Do we want to keep special hex printing for unsigned ints? In that case, the string method would have to be limited to Integers. |
Not a problem: julia> string(0xff)
"255" |
OT, but I still don't understand why it works this way, intead of of returning |
Because we don't consider |
As it turns out, this was a good choice as it allows us to fold |
base/libgit2/oid.jl
Outdated
""" | ||
raw(id::GitHash) -> Vector{UInt8} | ||
|
||
Obtain the raw bytes of the [`GitHash`](@ref) as a vector of length $OID_RAWSZ. | ||
""" | ||
raw(id::GitHash) = collect(id.val) | ||
|
||
Base.string(id::AbstractGitHash) = hex(id) | ||
Base.string(id::GitHash) = join([string(i, base = 16, pad = 2) for i in id.val]) | ||
Base.string(id::GitShortHash) = string(id.hash)[1:id.len] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the last discussion was to define Base.print(io::IO, id::GitHash)
(which implicitly defines Base.string
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no was it I'm so confused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g.
function Base.print(io::IO, id::GitHash)
for i in id.val
print(io, string(i, base = 16, pad = 2))
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though this makes me think that we should also have the same args to print
as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps best to leave that for another PR though
slayage |
It would probably be good to get this passing tests before making any further changes. Otherwise you're just making it harder to figure out which of the changes is causing the build failure. |
I just got through trying to build julia to help out with the debugging. These |
Thanks for taking the time to answer! But this moves my question to why |
People want some way to convert a number to just a digit string, with no decoration. It's less clear what to do with booleans. |
base/intfuncs.jl
Outdated
@@ -549,16 +549,14 @@ julia> ndigits(12345) | |||
julia> ndigits(1022, 16) | |||
3 | |||
|
|||
julia> base(16, 1022) | |||
julia> string(1022, bass = 16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
I don't understand the problem. If you want |
I'll try to rebase and fix this. |
Rebased: #25804 |
No description provided.