Re: pass by reference
- Posted by Irv Mullins <irvm at ellijay.com> Feb 12, 2002
- 600 views
On Tuesday 12 February 2002 12:07 pm, Bernie Ryan wrote: > > > I keep reading that you can't use pass by reference > in Euphoria. That is not true. You can use pass by > reference on any variable or atom or any fixed > length structure. The only thing you can't pass by > reference is a sequence because it is dynamic and > there is no way to control the errors that would > be caused by a user. The way you pass by reference > is to use allocates, peeks and pokes. er...no, that's pass-by-value. If I call foo(integer x) as follows: x = 3 foo(x) ? x => 3 No matter what happens inside the mysterious foo, x is still what it was before calling the function. Even if foo sets x to 99, it's only 99 while inside the foo routine. So foo is working with a copy of x, not the real x. Pass-by_reference passes the actual variable, not a copy, so that foo(var integer x) x = 99 end x = 3 foo(x) ? x => 99 The variable IS changed within the routine, and remains changed afterward. Regards, Irv