CoCoA:Var

From ApCoCoAWiki

Var

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 )  -- <quotes>call by reference</quotes>: The variable referred
    L := <quotes>new value</quotes>;       -- to by L is changed.
  EndDefine;
  M := <quotes>old value</quotes>;
  CallByRef(M);
  M;
new value
-------------------------------
  Define CallByVal(L)  -- <quotes>call by value</quotes>: The value of L is passed to
    L := <quotes>new value</quotes>;  -- the function.
    Return L;
  EndDefine;
  L := <quotes>old value</quotes>;
  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(<quotes>a string</quotes>) := 6;
  Var(<quotes>a string</quotes>);
6
-------------------------------
  P := Record[Name = <quotes>test</quotes>, Value = 1];
  X := <quotes>Name</quotes>;
  P.Var(X);
test
-------------------------------
  Var(<quotes>myring</quotes>) ::= Q[a,b];
  Var(<quotes>myring</quotes>);
Q[a,b]
-------------------------------
  Using Var(<quotes>myring</quotes>) Do (a+b)^2 EndUsing;
a^2 + 2ab + b^2
-------------------------------

Syntax

Var X
Var(X)
Var(S:STRING)

where X is the identifier of a CoCoA variable.

Define

RingEnv

   <type>function</type>
   <type>string</type>