Well, from this perspective, it makes sense why those strings should not
be mutable.
But from other perspectives, making strings immutable contradicts with
how natural languages are used. For instance, after I said "I am a
professor", I want to say "I am a scientist", or perhaps I change my
mind and say "I am a scholar".
Perhaps the key here is that we make a distinction between string and
word. It is totally understandable and reasonable that words are not
mutable. But a string, as a sentence, should not be immutable.
On 03/21/2014 09:09 PM, Ivar Nesje wrote:
We try to be helpful, and answer the questions as asked. We also
provide advice for improvements, if the question is likely to lead to
a poor program.
Julia gives you as a programmer lots of power, and if you don't follow
advice, you might end up in trouble.
If you change the internal representation of a string, you will run
into trouble in some parts of Julia, because we assume that strings
are immutable. If you never let other parts of Julia hold a reference
to the string while you are manipulating it, you should be alright.
eg.
a = Dict()
b = "hello"
a[b] = 1
b.data[5] = 'a'
will make the value in the dictionary inaccessible.
julia> a[b]
ERROR: key not found: "hella"
in getindex at dict.jl:586
julia> a["hello"]
ERROR: key not found: "hello"
in getindex at dict.jl:586
Ivar
kl. 13:42:23 UTC+1 fredag 21. mars 2014 skrev Andreas Lobinger følgende:
Hello colleagues,
this conversation is covering one of the most dangerous things
that you can do in SW engineering:
- How can i do X?
- This is not meant to be used. But i have a work around for you.
You can be absolutely sure that this will propagate and be the new
default way.
(I'm cleaning up other people's code at the moment, not julia, but
still...)