I’m learning lisp and have a question about a simple list:
(setq stuff '(one two three (+ 2 2)))
stuff ; prints "one two three (+ 2 2)"
(setq stuff (list `one `two `three (+ 2 2)))
stuff ; prints "one two three 4"
The first setq creates a list “one two three (+ 2 2)”. The second list creates “one two three 4”. Why does the first list not evaluate the (+ 2 2), but the second one does? I read in the Emacs Lisp intro documentation that when the list is built that it evaluates from the inside out. Why doesn’t the first list evaluate the addition before adding it to the list?
This is elisp in emacs 24.
'is not equivalent tolist, it’s shorthand forquote. You’re really doing this:The argument to quote is the expression
(one two three (+ 2 2)).From http://www.gnu.org/software/emacs/manual/html_node/elisp/Quoting.html: “The special form quote returns its single argument, as written, without evaluating it”.