[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:46:23 +0800 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Tue, Aug 11, 2015 at 08:21:53AM -0700, Ian Zimmerman wrote:
> On 2015-08-11 21:52 +0800, Navy Cheng wrote:
>
> > (setq a 1)
> > (setq b 2)
> > (setq c 3)
> >
> > How can I a alist, like:
> > ((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)))
>
> That's a strange question. Why would you want such a list, how would
> it be useful? To look up the value a a symbol, you just use it, for
> example:
I need to push some global variable to a "stack" and pop them later. If
I don't do like this, the global variables will be changed by program
> (setq a 1)
>
> ...
>
> (message "a=%d" a)
>
> => a=1
>
> In some special situations where a symbol is not evaluated (such as when
> playing with macros) you may need to use symbol-value. But I'm guessing
> you're not at that point.
>
My question has been solved. What I want is
(setq trees `((a . ,a) (b . ,b) (c . ,c)))
Thanks any way.