"Jason Creighton" <androflux / remove.to.reply.softhome.net> schrieb im
Newsbeitrag
news:20030612123014.33a6449b.androflux / remove.to.reply.softhome.net...
> On Thu, 12 Jun 2003 23:14:37 +0900
> Rasputin <rasputin / shrike.mine.nu> wrote:
>
> > > remember that pretty much everything is a reference and you won't go
far
> > > wrong
> >
> > I thought so, until this happened!
> > The array was full of references, so I thought el held the
> > reference from the Array.
> >
> > It seems to hold a copy of the reference...
>
> No, it doesn't. When you do a:

Sorry, but in fact you're wrong.  The reference is copied indeed.

> a = "Hello world, nice to meet you!".split(' ')
> a.each { |word| word = "lala" }
> p a
> ["Hello", "world,", "nice", "to", "meet", "you!"]
>
> You're binding word to a different object, not changing the objects
themselves.

Binding "word" to another object is indeed done by copying the reference
to the other object.  Or in other terms, after this assignment there is
one more reference to the object.

a="foo" # one ref to "foo"
b=b # two refs to "foo"
a=nil # one ref to "foo"
b=nil # zero refs to "foo"

I think you did want to say the right thing but mixed up terms a little.

Maybe Perl has contributed to the confusion since it in fact does some
aliasing of references in arrays on function invocations the allow a
function to change array element references directly by simply assigning.
IMHO the ruby way is much cleaner and easier to understand.

Kind regards

    robert