previous
next
|
Var
|
|
Syntax
|
Var X
Var(X)
Var(S:STRING)
where X is the identifier of a CoCoA variable.
|
Summary
|
function calls by reference, other complex referencing
|
Description
|
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.
|
Example
|
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:
|
Example
|
Var("a string") := 6;
Var("a string");
6
-------------------------------
P := Record[Name = 'test', Value = 1];
X := 'Name';
P.Var(X);
test
-------------------------------
Var('myring') ::= Q[a,b];
Var('myring');
Q[a,b]
-------------------------------
Using Var('myring') Do (a+b)^2 EndUsing;
a^2 + 2ab + b^2
-------------------------------
|
See also:
|
|