summaryrefslogtreecommitdiff
path: root/devdocs/elisp/global-variables.html
blob: 69a03e868d225cb985f96bf24d5f63ec770396b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 <h3 class="section">Global Variables</h3>  <p>The simplest way to use a variable is <em>globally</em>. This means that the variable has just one value at a time, and this value is in effect (at least for the moment) throughout the Lisp system. The value remains in effect until you specify a new one. When a new value replaces the old one, no trace of the old value remains in the variable. </p> <p>You specify a value for a symbol with <code>setq</code>. For example, </p> <div class="example"> <pre class="example">(setq x '(a b))
</pre>
</div> <p>gives the variable <code>x</code> the value <code>(a b)</code>. Note that <code>setq</code> is a special form (see <a href="special-forms">Special Forms</a>); it does not evaluate its first argument, the name of the variable, but it does evaluate the second argument, the new value. </p> <p>Once the variable has a value, you can refer to it by using the symbol itself as an expression. Thus, </p> <div class="example"> <pre class="example">x ⇒ (a b)
</pre>
</div> <p>assuming the <code>setq</code> form shown above has already been executed. </p> <p>If you do set the same variable again, the new value replaces the old one: </p> <div class="example"> <pre class="example">x
     ⇒ (a b)
</pre>
<pre class="example">(setq x 4)
     ⇒ 4
</pre>
<pre class="example">x
     ⇒ 4
</pre>
</div><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Global-Variables.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Global-Variables.html</a>
  </p>
</div>