[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: alists with precomputed variables
From: |
Drew Adams |
Subject: |
RE: alists with precomputed variables |
Date: |
Tue, 20 Jan 2009 21:13:35 -0800 |
> (setq my-var 20)
> (setq my-alist '((p1 . 10) (p2 . my-var)))
>
> I naively thought that would give me
> ((p1 . 10) (p2 . 20))
>
> but it instead results in
> ((p1 . 10) (p2 . my-var))
>
> How can I get what I expected?
(setq my-alist `((p1 . 10) (p2 ,@my-var)))
or (setq my-alist (list '(p1 . 10) (cons 'p2 my-var)))
or (setq my-alist (list (cons 'p1 10) (cons 'p2 my-var)))
See the Elisp manual, node Backquote for info about ` and ,@.
See also nodes Quoting and Building Lists.