From: "Mauricio Fernández" Date: 2002-10-23T21:09:02+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) On Wed, Oct 23, 2002 at 06:28:29PM +0900, Bulat Ziganshin wrote: > Hello Ian, > > Tuesday, October 22, 2002, 7:30:19 AM, you wrote: > > IM> I understand that, but since 'a' already exists prior to assigning a + b > IM> to it, why does it need to be recreated? Where strings are concerned, > IM> I don't see why this would be any different to 'a << b'. > > main problem is that object pointed by 'a' mauy be also pointed by > another variable an if you change this object directly your code wil > have SIDE EFFECT. are you really need this? :) so '<<' and other > methods changing object itself must be used very carefully, preferably > for local variables and other "own" objects > > example of this side effect: > > def a(s) > s << '!' > s += '?' > return s > end > > x='1' > y=a(x) > p x,y Would it be possible for Ruby to know whether an object is referenced by several variables so += does '<<' or '... = ... + ...' when appropriate? Perhaps a bit in each String indicating whether it is shared or not would make it... and GC issues could be ignored at first. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com The most important design issue... is the fact that Linux is supposed to be fun... -- Linus Torvalds at the First Dutch International Symposium on Linux