-
-
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
copy not implemented for String #31995
Comments
I've tried to avoid defining |
I have a variable There is some precedence for defining copied_string(x) = String(copy(x))
copied_string(x::String) = x which works fine but just feels a bit too verbose. Maybe there already exists a more convenient way to achieve this? |
I still worry that this is overly pedantic. I guess the argument is something along these lines... If you're copying something, then it must be because you're going to mutate it—otherwise why copy it? But if some of the values are immutable, then that's going to fail anyway, so what kind of code needs this? |
|
Indeed, if |
We already have lots of julia> copy(3)
3
julia> copy(1:10)
1:10 On the other hand, julia> Base.copymutable("Hello")
5-element Array{Char,1}:
'H': ASCII/Unicode U+0048 (category Lu: Letter, uppercase)
'e': ASCII/Unicode U+0065 (category Ll: Letter, lowercase)
'l': ASCII/Unicode U+006C (category Ll: Letter, lowercase)
'l': ASCII/Unicode U+006C (category Ll: Letter, lowercase)
'o': ASCII/Unicode U+006F (category Ll: Letter, lowercase) (Maybe in Julia 2.0 we can make |
For example, |
I don't get what point you are trying to make. That there should be a generic
Yes:
|
Yes, i.e. generic code was relying on those methods, so they can't have been that useless. |
Yes, they could have been? People do useless stuff all the time. Just look at one of the logs from PkgEval for an upcoming release. |
In this case it was a Vector that needed to be copied, not a String, so I'm inclined to close this. I'm not a fan of the default |
Which is exactly what you want if you want a mutable copy … recall that |
As stated above, in the use case I had I needed to copy an array to make sure it is not invalidated when passed to a
So it is explicitly suggested to call I agree we might close this issue or rename it to something Make String constructor copy by default or refer to an already existing issue that discusses this. |
|
The I don't think methods should be added for the convenience of not writing a branch when a function doesn't apply to one case. |
I just realized this on Julia 1.1 as well as master:
I was wondering if this is desired behavior or would if it would be ok to define
copy(s::String)=s
since Strings are immutable.The text was updated successfully, but these errors were encountered: