File: ch06s08.html

package info (click to toggle)
genius 1.0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, 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 (22 lines) | stat: -rw-r--r-- 3,216 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
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Referencias</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Manual de Genius"><link rel="up" href="ch06.html" title="Chapter 6. Programar con GEL"><link rel="prev" href="ch06s07.html" title="Retorno"><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">Referencias</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06s07.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Programar con 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>Referencias</h2></div></div></div><p>Para algunas funciones puede ser necesario devolver más de un valor. Esto se puede lograr al devolver un vector de valores, pero muchas veces resulta conveniente pasar una referencia a una variable. Puede pasar una referencia a una variable a una función, y la función fijará el valor, eliminando una referencia. Aunque éste es el principal uso de las referencias, no es el único.</p><p lang="en">
	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 lang="en" class="programlisting">RayleighQuotientIteration (A,x,0.001,100,&amp;v)
</pre><p lang="en">
      </p><p>La manera como funcionan las referencias y la sintaxis que utilizan son similares al lenguaje C. El operador <code class="literal">&amp;</code> hace referencia a una variable y <code class="literal">*</code> la elimina. Ambos pueden aplicarse sólo a un identificador, por lo que <code class="literal">**a</code> no es una expresión legal en GEL.</p><p lang="en">
References are best explained by an example:
</p><pre lang="en" class="programlisting">a=1;
b=&amp;a;
*b=2;
</pre><p lang="en">
now <code class="varname">a</code> contains 2.  You can also reference functions:
</p><pre lang="en" class="programlisting">function f(x) = x+1;
t=&amp;f;
*t(3)
</pre><p lang="en">
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">Retorno </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>