Assign values to variables
Set
(Set arg1 arg2) this syntax sets arg2 to the value of arg1
For example:
(Set 'flowers' (Rose viletdaisy Buttercup ))
This is the creation of a symbol flowers, which assigns the (Rose viletting Daisy Buttercup) list to the value field of flowers.
Later, you can directly use flowers, just like using a variable, which is actually a list stored in its value field, for example:
(Print flowers)
Also output (Rose VILET Daisy Buttercup)
Note that the single quotes here tell the parser not to try to evaluate flowers and (Rose viotlet Daisy Buttercup.
If the set statement removes the single quotes before flowers, flowers will be evaluated. Because flowers has not been defined, the evaluation will be incorrect and the following error will be displayed:
Error: (void-variable flowers)
It should be well understood.
Setq
The setq statement is a simplified version of set. If the first parameter of set needs to be enclosed by single quotation marks, setq can be used to simplify it. For example:
(Setq Flowers' (Rose viletdaisy Buttercup ))
Setq also supports defining multiple symbrs at a time, for example:
(Setq trees '(pine fir oak maple) herbivores' (gazelle antelope zebra ))
Defvar
Different from set:
1. If a variable has no value, assign it the initial value.
2. If a variable already has a value, nothing will be done.
3. A string parameter is provided to describe this variable.
(Defvar variable name variable value "variable description ")
C-h v can see the description of this variable.