[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to use a symbol and its value to create alist?
From: |
Pascal J. Bourguignon |
Subject: |
Re: How to use a symbol and its value to create alist? |
Date: |
Tue, 11 Aug 2015 16:39:45 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Navy Cheng <navych@126.com> writes:
> For example:
>
> (setq a 1)
> (setq b 2)
> (setq c 3)
>
> How can I a alist, like:
How can you WHAT a alist?
> ((a . 1) (b . 2) (c .3))
>
> The value of a, b and c may change, so don't do this like
> (setq tree ((a . 1) (b . 2) (c .3)))
This is not a valid form, because (a . 1) is not a function name,
therefore it's not possible to apply it.
If you want to BUILD an a-list, you can use acons:
(let ((a 1)
(b 2)
(c 3))
(let ((tree (acons 'a a (acons 'b b (acons 'c c '())))))
tree))
--> ((a . 1) (b . 2) (c . 3))
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk