[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: |
Navy Cheng |
Subject: |
Re: How to use a symbol and its value to create alist? |
Date: |
Wed, 12 Aug 2015 09:57:13 +0800 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Tue, Aug 11, 2015 at 04:39:45PM +0200, Pascal J. Bourguignon wrote:
> 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?
Sorry for that, (setq WHAT "create")
>
> > ((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.
>
Sorry again, (setq tree '((a . 1) (b . 2) (c .3)))
>
> 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))
>
Thanks for your patient and help. Your answer is OK. I have learned
another way to do this.
(setq tree `((a . ,a) (b . ,b) (c . ,c)))