up previous next
function calls by reference, other complex referencing
Var X
Var(X)
Var(S:STRING)
where X is the identifier of a CoCoA variable.
|
In the first and second form
Var 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(Var L ) -- "call by reference": The variable referred
L := "new value"; -- to by L is changed.
EndDefine;
M := "old value";
CallByRef(M);
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.
-------------------------------
|
In the third form, Var(S), references the value of the variable or ring
whose identifier is S:
Var("a string") := 6;
Var("a string");
6
-------------------------------
P := Record[Name = "test", Value = 1];
X := "Name";
P.Var(X);
test
-------------------------------
Var("myring") ::= QQ[a,b];
Var("myring");
QQ[a,b]
-------------------------------
Using Var("myring") Do (a+b)^2 EndUsing;
a^2 + 2ab + b^2
-------------------------------
|