It may be necessary for some functions to return more than one value. This may be accomplished by returning a vector of values, but many times it is convenient to use passing a reference to a variable. You pass a reference to a variable to a function, and the function will set the variable for you using a dereference. You do not have to use references only for this purpose, but this is their main use.
When using functions that return values through references
in the argument list, just pass the variable name with an ampersand.
For example the following code will compute an eigenvalue of a matrix
A with initial eigenvector guess
x, and store the computed eigenvector
into the variable named
The details of how references work and the syntax is similar to the C language.
& references a variable
* dereferences a variable. Both can only be applied to an identifier,
**a is not a legal expression in GEL.
References are best explained by an example:
a=1; b=&a; *b=2;
a contains 2. You can also reference functions:
function f(x) = x+1; t=&f; *t(3)
gives us 4.