From: "Hal E. Fulton" Date: 2002-10-22T13:02:06+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) ----- Original Message ----- From: "Ian Macdonald" To: "ruby-talk ML" Sent: Monday, October 21, 2002 10:30 PM Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) > On Tue 22 Oct 2002 at 12:18:22 +0900, Hal E. Fulton wrote: > > > ----- Original Message ----- > > From: "Ian Macdonald" > > To: "ruby-talk ML" > > Sent: Monday, October 21, 2002 10:03 PM > > Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) > > > > > > > Hmm, why does 'string += another' need to create a new object? string > > > already exists, so wouldn't the reference simply be updated? > > > > It's a feature. :) The notation a+=b really, REALLY > > means a = a + b. > > I understand that, but since 'a' already exists prior to assigning a + b > to it, why does it need to be recreated? Where strings are concerned, > I don't see why this would be any different to 'a << b'. Look at it this way: The expression a + b yields a new object, does it not? You wouldn't want a + b simply to append b onto a, would you? The new object which we describe as a + b has no way of knowing that it's about to be assigned back to variable a. It might conceptually be possible to have the interpreter "optimize" a+=b into a<