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

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

Drew
  • 75,699
  • 9
  • 109
  • 225
FaiChou
  • 113
  • 2
  • 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 '19 at 20:57

1 Answers1

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))
lawlist
  • 18,826
  • 5
  • 37
  • 118