Strings are immutable, but `isimmutable("abc")` still returns false -- why?



As per the title: The Julia manual for 1.0 explicitly says that “As in Java, strings are immutable”. And experimentally, I indeed can’t seem to modify a string (other than perhaps using some unsafe function, but of course if one really insists on shooting oneself into the foot, then one usually can, so I’ll not mind that). Anyway, despite all this, isimmutable("abc") still returns false – why?

I am kinda hoping this is a bug, but if not, I’d really like to understand what’s going on, and perhaps the documentation can then be improved to clarify this.

While I am at it, to quote some more documentation, this time for isimmutable:

Return true iff value v is immutable. See Mutable Composite Types for a discussion of immutability. Note that this function works on values, so if you give it a type, it will tell you that a value of DataType is mutable.

I don’t quite understand the very end of this: “… it will tell you that a value of DataType is mutable.” Perhaps this is meant to be say something close to “… it will tell you whether instances of this type are mutable”, or perhaps “… then for a DataType, it will tell you whether instances of that type are mutable, even though the type object itself is immutable”. Is that correct? If not, what else is meant?


Yes, I think this is an oversight accidentally left over from past versions when strings were mutable.


Also, is

julia> isstructtype(String)



Issue filed: Thanks for pointing this out.


OK… So I tried to figure out where this is set, and while doing this, notice this line, which indicates the symbols also are considered mutable, but apparently intentionally so?!

src/jltypes.c:1765:    jl_sym_type->mutabl = 1;

Indeed, we get:

julia> isimmutable(:abc)


I’ve added that observation to the issue. Probably best to continue discussion over there.