[Issue 3814] Mutation of immutable string

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 18 11:23:11 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3814


Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com


--- Comment #3 from Steven Schveighoffer <schveiguy at yahoo.com> 2010-02-18 11:23:09 PST ---
It does have immutable traits.  With D's immutable strings, the *shared* part
is immutable.  That is, you can share strings because of the hybrid
value/reference type that is an array (shared data, local length).  It's a very
different concept to other programming languages.

Because strings are not true reference types, changing the length of one string
does not affect another string, even if both point to the same data.

Think about how Java has immutable strings, but you can reassign a string
variable.  That does not make the strings themselves not immutable!  However,
immutable strings in Java are pure reference types (even the length is shared),
so in order to take a "slice" of a string, you must make an entirely new
object, but the same data (except for the length) is referenced.  The same is
not true in D where the string length is not shared, and therefore does not
need to be immutable.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list