Next: , Up: Variables   [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 is a special form (see Special Forms); it 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 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:

     ⇒ (a b)
(setq x 4)
     ⇒ 4
     ⇒ 4