Pro některé funkce je nutné, aby vracely více než jednu hodnotu. To lze zajistit vrácením vektoru hodnot, ale častokrát je praktičtější použít předávání reference (odkazu) na proměnnou. Předáte funkci referenci na proměnnou a funkce proměnnou nastaví pomocí dereference. Nemusíte se s používáním referencí omezovat jen na tento účel, ale tohle je jejich hlavní využití.
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 v
:
RayleighQuotientIteration (A,x,0.001,100,&v)
V detailech fungování a syntaxi jsou reference podobné jako v jazyku C. Operátor &
odkazuje na proměnnou a *
provádí dereferenci proměnné. Obojí lze uplatnit pouze na identifikátory, takže **a
není v jazyce GEL platný výraz.
References are best explained by an example:
a=1;
b=&a;
*b=2;
now a
contains 2. You can also reference functions:
function f(x) = x+1;
t=&f;
*t(3)
gives us 4.