RE: pass by reference Karl
- Posted by Bernie Ryan <xotron at localnet.com> Feb 12, 2002
- 474 views
kbochert at ix.netcom.com wrote: > -------Phoenix-Boundary-07081998- > Content-type: text/plain; charset=ISO-8859-1 > Content-transfer-encoding: 8bit > > Hi Irv Mullins, you wrote on 2/12/02 10:26:37 AM: > > >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 > > In my implementation, pass-by reference is accomplished by > the caller. That is: > > procedure foo (sequence x) > x = x[2..3] > end procedure > > sequence s = "test" > foo (s) > -- s still equals "test" > > foo (!!s) > -- s now equals "es" > > Library routines can never do something behind your > back. > > The other not-so-minor detail is that only sequences > can be passed by reference. Karl: What happens when a user does slicing, append, prepend on the sequence that is passed. Don't forget that sequences are dynamic and are reallocated dynamically. Bernie