GNU Info

Info Node: (elisp)Accessing Variables

(elisp)Accessing Variables


Next: Setting Variables Prev: Tips for Defining Up: Variables
Enter node , (file) or (file)node

Accessing Variable Values
=========================

   The usual way to reference a variable is to write the symbol which
names it (Note: Symbol Forms).  This requires you to specify the
variable name when you write the program.  Usually that is exactly what
you want to do.  Occasionally you need to choose at run time which
variable to reference; then you can use `symbol-value'.

 - Function: symbol-value symbol
     This function returns the value of SYMBOL.  This is the value in
     the innermost local binding of the symbol, or its global value if
     it has no local bindings.

          (setq abracadabra 5)
               => 5
          (setq foo 9)
               => 9
          
          ;; Here the symbol `abracadabra'
          ;;   is the symbol whose value is examined.
          (let ((abracadabra 'foo))
            (symbol-value 'abracadabra))
               => foo
          
          ;; Here the value of `abracadabra',
          ;;   which is `foo',
          ;;   is the symbol whose value is examined.
          (let ((abracadabra 'foo))
            (symbol-value abracadabra))
               => 9
          
          (symbol-value 'abracadabra)
               => 5

     A `void-variable' error is signaled if the current binding of
     SYMBOL is void.


automatically generated by info2www version 1.2.2.9