gpt4 book ai didi

emacs - 列表项评估

转载 作者:太空宇宙 更新时间:2023-11-03 18:49:06 27 4
gpt4 key购买 nike

我正在学习 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),而第二个列表计算?我在 Emacs Lisp 介绍文档中读到,当构建列表时,它会从内到外进行评估。为什么第一个列表在添加到列表之前不评估添加?

这是 emacs 24 中的 elisp。

最佳答案

' 不等同于 list,它是 quote 的简写。你真的在这样做:

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

quote 的参数是表达式 (one two three (+ 2 2))

来自 http://www.gnu.org/software/emacs/manual/html_node/elisp/Quoting.html : "特殊形式的 quote 返回它的单个参数,如所写的那样,而不对其求值。

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com