GNU Info

Info Node: (emacs-lisp-intro.info)Using set

(emacs-lisp-intro.info)Using set


Next: Using setq Prev: set & setq Up: set & setq
Enter node , (file) or (file)node

Using `set'
-----------

   To set the value of the symbol `flowers' to the list `'(rose violet
daisy buttercup)', evaluate the following expression by positioning the
cursor after the expression and typing `C-x C-e'.

     (set 'flowers '(rose violet daisy buttercup))

The list `(rose violet daisy buttercup)' will appear in the echo area.
This is what is _returned_ by the `set' function.  As a side effect,
the symbol `flowers' is bound to the list ; that is, the symbol
`flowers', which can be viewed as a variable, is given the list as its
value.  (This process, by the way, illustrates how a side effect to the
Lisp interpreter, setting the value, can be the primary effect that we
humans are interested in.  This is because every Lisp function must
return a value if it does not get an error, but it will only have a
side effect if it is designed to have one.)

   After evaluating the `set' expression, you can evaluate the symbol
`flowers' and it will return the value you just set.  Here is the
symbol.  Place your cursor after it and type `C-x C-e'.

     flowers

When you evaluate `flowers', the list `(rose violet daisy buttercup)'
appears in the echo area.

   Incidentally, if you evaluate `'flowers', the variable with a quote
in front of it, what you will see in the echo area is the symbol itself,
`flowers'.  Here is the quoted symbol, so you can try this:

     'flowers

   Note also, that when you use `set', you need to quote both arguments
to `set', unless you want them evaluated.  Since we do not want either
argument evaluated, neither the variable `flowers' nor the list `(rose
violet daisy buttercup)', both are quoted.  (When you use `set' without
quoting its first argument, the first argument is evaluated before
anything else is done.  If you did this and `flowers' did not have a
value already, you would get an error message that the `Symbol's value
as variable is void'; on the other hand, if `flowers' did return a
value after it was evaluated, the `set' would attempt to set the value
that was returned.  There are situations where this is the right thing
for the function to do; but such situations are rare.)


automatically generated by info2www version 1.2.2.9