> >> This won't work in Ruby. If you call swap(a[i], a[j]), two
> >> variables x and y are created, and the values of a[i] and a[j]
> >> are copied to it. Executing the body effectively interchanges the
> >> values of x and y, but not those of a[i] and a[j]. Consider
> >> replacing a call to swap with a simple
> > If function are params are only copies, why do the two functions
> > below behave differently:
>
> Function params aren't copies; they are (1) variables that (2)
> contain references to objects. Remember that in Ruby, variables are
> just tags that refer to objects. They aren't memory slots in and of
> themselves like they are in other languages.

Sorry for the confusion. To me the value of a variable is a reference to
an object, not the object itself. And on method call, references are
copied to variables with the same name as the formal parameters. To me
that's the simplest and most consistent view. But I can see how my
explanation above can be confusing...

Peter