我正在学习lisp,有一个关于简单列表的问题:

(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"

第一个setq创建一个列表“一二三(+2 2)”第二个列表创建“一二三四”为什么第一个列表不评估(+2 2),而第二个列表评估(+2 2 2)我在Emacs Lisp简介文档中读到,当构建列表时,它会从内到外进行评估为什么第一个列表在将其添加到列表之前不对其进行评估?
我是Emacs24的elisp。

最佳答案

'不等同于list,它是quote的简写你真的这么做了:

(setq stuff (quote (one two three (+ 2 2))))

引用的参数是表达式(one two three (+ 2 2))
http://www.gnu.org/software/emacs/manual/html_node/elisp/Quoting.html:“特殊形式的引号返回其单个参数,如所写,而不计算它”。

关于emacs - list 项目评估,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14106386/

10-14 07:55