On Thu, Dec 04, 2003 at 07:24:28PM +0900, Peter wrote:
> [snip]
> > To swap two numbers x and y, call
> >
> > swap(x,y)
> > z = x
> > x = y
> > y = z
> > end
> 
> 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:
 
	def f1(a)
	 a=[9,8,7]
	end

	def f2(b)
	 b[0]=[9,8,7]
	end
  
	v=[1,2,3]
	f1(v)
	 p v    		# prints [1,2,3]  :  'v' not changed
	f2(v)
	 p v		        # prints [[9,8,7],2,3] !