Re: Immutability and strings

2010-08-23 Thread Steven Schveighoffer
On Wed, 18 Aug 2010 22:11:35 -0400, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Here's something from TDPL, page 292: string process(string input) { return input; }; string s1 = blah; string s2 = process(s1); assert(s1 == blah); // never fails I've added the return in process(), it

Immutability and strings

2010-08-18 Thread Andrej Mitrovic
Here's something from TDPL, page 292: string process(string input) { return input; }; string s1 = blah; string s2 = process(s1); assert(s1 == blah); // never fails I've added the return in process(), it wasn't there. Andrei states that it's impossible for s2 to be changed after the

Re: Immutability and strings

2010-08-18 Thread Jonathan M Davis
On Wednesday, August 18, 2010 19:11:35 Andrej Mitrovic wrote: It's just nitpicking, I know. And I'm sure Andrei was specifically documenting only that first example. But I do think it was worth mentioning that immutability on individual elements isn't a safe bet unless you're sure the function

Re: Immutability and strings

2010-08-18 Thread Kagamin
Andrej Mitrovic Wrote: I agree that in this case s1 and s2 will remain the same. But this has to do *not just* with immutability, but with the fact that s1 is passed by value. I think that should be mentioned here. In the first example a string reference is passed by value. In the second