RE: pass by reference Karl

new topic     » topic index » view thread      » older message » newer message

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

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu