Debian Codegraph @

help/pt_BR/html/ch05s02.html

raw
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Using Variables</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Manual do Genius"><link rel="up" href="ch05.html" title="Chapter 5. GEL Basics"><link rel="prev" href="ch05.html" title="Chapter 5. GEL Basics"><link rel="next" href="ch05s03.html" title="Using Functions"></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">Using Variables</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch05.html">Prev</a> </td><th width="60%" align="center">Chapter 5. GEL Basics</th><td width="20%" align="right"> <a accesskey="n" href="ch05s03.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-variables"></a>Using Variables</h2></div></div></div><p lang="en">
2 Syntax:
3 </p><pre lang="en" class="programlisting">VariableName
4 </pre><p lang="en">
5 Example:
6 </p><pre lang="en" class="screen"><code class="prompt">genius&gt; </code><strong class="userinput"><code>e</code></strong>
7 = 2.71828182846
8 </pre><p lang="en">
9 </p><p lang="en">
10 To evaluate a variable by itself, just enter the name of the variable. This will return the value of the variable. You can use a variable anywhere you would normally use a number or string. In addition, variables are necessary when defining functions that take arguments (see <a class="xref" href="ch05s03.html#genius-gel-functions-defining" title="Defining Functions">the section called “Defining Functions”</a>).
11 </p><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Using Tab completion</h3><p lang="en">
12 You can use Tab completion to get Genius to complete variable names for you. Try typing the first few letters of the name and pressing <strong class="userinput"><code>Tab</code></strong>.
13 </p></div><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Variable names are case sensitive</h3><p lang="en">
14 The names of variables are case sensitive. That means that variables named <code class="varname">hello</code>, <code class="varname">HELLO</code> and <code class="varname">Hello</code> are all different variables.
15 </p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-variables-setting"></a>Setting Variables</h3></div></div></div><p lang="en">
16 Syntax:
17 </p><pre lang="en" class="programlisting">&lt;identifier&gt; = &lt;value&gt;
18 &lt;identifier&gt; := &lt;value&gt;
19 </pre><p lang="en">
20 Example:
21 </p><pre lang="en" class="programlisting">x = 3
22 x := 3
23 </pre><p lang="en">
24 </p><p lang="en">
25 To assign a value to a variable, use the <code class="literal">=</code> or <code class="literal">:=</code> operators. These operators set the value of the variable and return the value you set, so you can do things like
26 </p><pre lang="en" class="programlisting">a = b = 5
27 </pre><p lang="en">
28 This will set <code class="varname">b</code> to 5 and then also set <code class="varname">a</code> to 5.
29 </p><p lang="en">
30 The <code class="literal">=</code> and <code class="literal">:=</code> operators can both be used to set variables. The difference between them is that the <code class="literal">:=</code> operator always acts as an assignment operator, whereas the <code class="literal">=</code> operator may be interpreted as testing for equality when used in a context where a Boolean expression is expected.
31 </p><p lang="en">
32 For more information about the scope of variables, that is when are what variables visible, see <a class="xref" href="ch06s05.html" title="Global Variables and Scope of Variables">the section called “Global Variables and Scope of Variables”</a>.
33 </p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-variables-built-in"></a>Built-in Variables</h3></div></div></div><p lang="en">
34 GEL has a number of built-in ‘variables’, such as
35 <code class="varname">e</code>, <code class="varname">pi</code> or <code class="varname">GoldenRatio</code>. These are widely used constants with a preset value, and
36 they cannot be assigned new values.
37 There are a number of other built-in variables.
38 See <a class="xref" href="ch11s04.html" title="Constantes">the section called “Constantes”</a> for a full list. Note that <code class="varname">i</code> is not by default
39 the square root of negative one (the imaginary number), and is undefined to allow its use as a counter. If you wish to write the imaginary number you need to
40 use <strong class="userinput"><code>1i</code></strong>.
41 </p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-previous-result"></a>Previous Result Variable</h3></div></div></div><p lang="en">
42 The <code class="varname">Ans</code> and <code class="varname">ans</code> variables can be used to get the result of the last expression. For example, if you had performed some calculation, to add 389 to the result you could do:
43 </p><pre lang="en" class="programlisting">Ans+389
44 </pre><p lang="en">
45 </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch05.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch05s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 5. GEL Basics </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Using Functions</td></tr></table></div></body></html>