Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 4040

Macaulay2-1.3.1-8.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8" ?>  <!-- for emacs: -*- coding: utf-8 -*- -->
<!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"	 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>assigning values</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="_local_spvariables_spin_spa_spfile.html">next</a> | <a href="_valid_spnames.html">previous</a> | <a href="_local_spvariables_spin_spa_spfile.html">forward</a> | <a href="_valid_spnames.html">backward</a> | <a href="_variables.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div>

    </td>
  </tr>
</table>
<div><a href="index.html" title="">Macaulay2Doc</a> > <a href="___The_sp__Macaulay2_splanguage.html" title="">The Macaulay2 language</a> > <a href="_variables.html" title="The variables of a complex or co-complex.">variables</a> > <a href="_assigning_spvalues.html" title="">assigning values</a></div>
<hr/>
<div><h1>assigning values</h1>
<div>Use an equal sign to assign values to variables.<table class="examples"><tr><td><pre>i1 : x = "abcde"

o1 = abcde</pre>
</td></tr>
<tr><td><pre>i2 : x

o2 = abcde</pre>
</td></tr>
</table>
Before assignment, any reference to a variable provides the symbol with that name.  After assignment, the assigned value is provided.  The variable created is global, in the sense that any code placed elsewhere that contains a reference to a variable called <tt>x</tt> will refer to the one we just set.<p/>
It is important to distinguish between a symbol and its value.  The initial value of a global symbol is the symbol itself, and the initial value of a local variable is <a href="_null.html" title="the unique member of the empty class">null</a>.  One possibility for confusion comes from the possibility of having a symbol whose value is another symbol; it's even more confusing if the two symbols have the same name but different scopes, for example, if one of them is global and the other is local.<table class="examples"><tr><td><pre>i3 : y

o3 = y

o3 : Symbol</pre>
</td></tr>
<tr><td><pre>i4 : y = z

o4 = z

o4 : Symbol</pre>
</td></tr>
<tr><td><pre>i5 : y

o5 = z

o5 : Symbol</pre>
</td></tr>
<tr><td><pre>i6 : z = 444

o6 = 444</pre>
</td></tr>
<tr><td><pre>i7 : z

o7 = 444</pre>
</td></tr>
<tr><td><pre>i8 : y

o8 = z

o8 : Symbol</pre>
</td></tr>
</table>
In the example above, the final value of <tt>y</tt> is the symbol <tt>z</tt>, even though the symbol z has acquired a value of its own.  The function <tt>value</tt> can be used to get the value of a symbol.<table class="examples"><tr><td><pre>i9 : value y

o9 = 444</pre>
</td></tr>
</table>
The operator <a href="__lt-.html" title="assignment with left side evaluated">&lt;-</a> can be used to set the value of a symbol.  This operator differs from <a href="__eq.html" title="assignment">=</a> in that the symbol or expression on the left hand side is evaluated.<table class="examples"><tr><td><pre>i10 : y &lt;- 555

o10 = 555</pre>
</td></tr>
<tr><td><pre>i11 : y

o11 = z

o11 : Symbol</pre>
</td></tr>
<tr><td><pre>i12 : z

o12 = 555</pre>
</td></tr>
<tr><td><pre>i13 : y = 666

o13 = 666</pre>
</td></tr>
<tr><td><pre>i14 : y

o14 = 666</pre>
</td></tr>
<tr><td><pre>i15 : z

o15 = 555</pre>
</td></tr>
</table>
One reason the user needs to understand this concept is that assignments with the operator <a href="__lt-.html" title="assignment with left side evaluated">&lt;-</a> are occasionally done on the user's behalf by bits of code already in the system, for example, when creating a polynomial ring the prospective variables are given new values that are the generators of the polynomial ring.<p/>
</div>
<div class="single"><h2>See also</h2>
<ul><li><span><a href="___Global__Assign__Hook.html" title="hook for assignment to global variables">GlobalAssignHook</a> -- hook for assignment to global variables</span></li>
<li><span><a href="___Global__Release__Hook.html" title="">GlobalReleaseHook</a></span></li>
</ul>
</div>
</div>
</body>
</html>