Elisp programming 6: defining variables

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.