Re: pass by reference
-------Phoenix-Boundary-07081998-
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.
I have never heard of a language doing it this way
and intrigued by the possibilities.
Karl
-------Phoenix-Boundary-07081998---
|
Not Categorized, Please Help
|
|