up previous next
function calls by reference
ref X
where X is the identifier of a CoCoA variable.
|
In the first and second form
ref
is used as a formal parameter to a
user-defined function. It is used to pass a variable---not its
value---to the user-defined function. The following example should
make the difference clear.
Define CallByRef(ref L) -- "call by reference": The variable referred
L := "new value"; -- to by L is changed.
EndDefine;
M := "old value";
/**/ CallByRef(ref M); -- here "ref" recalls that M might change
/**/ M;
new value
Define CallByVal(L) -- "call by value": The value of L is passed to
L := "new value"; -- the function.
Return L;
EndDefine;
L := "old value";
/**/ CallByVal(L);
new value
/**/ L;
old value
|