up previous next
passing function parameters by reference
where X is the identifier of a CoCoA variable.
is used to pass a parameter "by reference" to a
function which may modify its value (e.g.
alerts the programmer to the possibility that the
value may be changed during the call.
To write a new function which can modify some parameters use the same
to identify which formal parameters are to be passed
by reference. The following example illustrates the difference between
passing by reference and passing by value.
/**/ Define CallByRef(ref L) -- "call by reference": The variable referred
/**/ L := "new value"; -- to by L is changed.
/**/ M := "old value";
/**/ CallByRef(ref M); -- here "ref" recalls that M might change
/**/ PrintLn M;
/**/ Define CallByVal(L) -- "call by value": The value of L is passed to
/**/ L := "new value"; -- the function.
/**/ Return L;
/**/ L := "old value";
/**/ PrintLn L;