File: ch06s08.html

package info (click to toggle)
genius 1.0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 25,308 kB
  • sloc: ansic: 75,620; xml: 71,565; sh: 4,445; makefile: 1,927; lex: 523; yacc: 298; perl: 54
file content (35 lines) | stat: -rw-r--r-- 3,156 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>References</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Genius Manual"><link rel="up" href="ch06.html" title="Chapter 6. Programming with GEL"><link rel="prev" href="ch06s07.html" title="Returning"><link rel="next" href="ch06s09.html" title="Lvalues"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">References</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06s07.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Programming with GEL</th><td width="20%" align="right"> <a accesskey="n" href="ch06s09.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="genius-gel-references"></a>References</h2></div></div></div><p>
	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.
      </p><p>
	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
	<code class="varname">A</code> with initial eigenvector guess
	<code class="varname">x</code>, and store the computed eigenvector
	into the variable named <code class="varname">v</code>:
</p><pre class="programlisting">RayleighQuotientIteration (A,x,0.001,100,&amp;v)
</pre><p>
      </p><p>
The details of how references work and the syntax is similar to the C language.
The operator
<code class="literal">&amp;</code> references a variable
and <code class="literal">*</code> dereferences a variable. Both can only be applied to an identifier,
so <code class="literal">**a</code> is not a legal expression in GEL.
      </p><p>
References are best explained by an example:
</p><pre class="programlisting">a=1;
b=&amp;a;
*b=2;
</pre><p>
now <code class="varname">a</code> contains 2.  You can also reference functions:
</p><pre class="programlisting">function f(x) = x+1;
t=&amp;f;
*t(3)
</pre><p>
gives us 4.
      </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch06s07.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch06.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch06s09.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Returning </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Lvalues</td></tr></table></div></body></html>