www.delorie.com/gnu/docs/elisp-manual-21/elisp_139.html   search  
 
Buy the book!


GNU Emacs Lisp Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.1 Global Variables

The simplest way to use a variable is globally. 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.

You specify a value for a symbol with setq. For example,

 
(setq x '(a b))

gives the variable x the value (a b). Note that setq does not evaluate its first argument, the name of the variable, but it does evaluate the second argument, the new value.

Once the variable has a value, you can refer to it by using the symbol by itself as an expression. Thus,

 
x => (a b)

assuming the setq form shown above has already been executed.

If you do set the same variable again, the new value replaces the old one:

 
x
     => (a b)
(setq x 4)
     => 4
x
     => 4


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003