1
(setq a 2)
(setq l '(a b c))
(car l)

Got a when evaluating this, and why its value not 2 ?

1
  • I didn't think this was completely a duplicate at first. But since OP wants to evaluate a variable that's in the list being quoted, it is.
    – Drew
    Oct 31, 2019 at 20:57

1 Answer 1

3

The single quote inhibits evaluation of elements in the list. An alternative form would be to use the function list instead of single quote, or use a backtick and comma combination. See:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html

(progn
  (setq a 2)
  (setq l `(,a b c))
  (car l))

or

(let (a b c l)
  (setq a 2)
  (setq l (list a b c))
  (car l))

Not the answer you're looking for? Browse other questions tagged or ask your own question.