在 Lisp(Clojure、Emacs Lisp)中,list 和 quote 有什么区别? [英] In Lisp (Clojure, Emacs Lisp), what is the difference between list and quote?

查看:26
本文介绍了在 Lisp(Clojure、Emacs Lisp)中,list 和 quote 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过阅读有关 Lisp 的介绍性材料,我现在认为以下内容是相同的:

(列表 1 2 3)'(1 2 3)

然而,从我在 Clojure 和 Emacs Lisp 中使用引用形式时遇到的问题来看,它们相同.你能告诉我有什么区别吗?

解决方案

主要区别在于 quote 阻止对元素进行评估,而 list不会:

<前>用户=> '(1 2 (+ 1 2))(1 2 (+ 1 2))用户=> (列表 1 2 (+ 1 2))(1 2 3)

出于这个原因(除其他外),在描述文字集合时使用向量是惯用的clojure:

<前>用户=> [1 2 (+ 1 2)][1 2 3]

From reading introductory material on Lisp, I now consider the following to be identical:

(list 1 2 3)

'(1 2 3)

However, judging from problems I face when using the quoted form in both Clojure and Emacs Lisp, they are not the same. Can you tell me what the difference is?

解决方案

The primary difference is that quote prevents evaluation of the elements, whereas list does not:

user=> '(1 2 (+ 1 2))
(1 2 (+ 1 2))
user=> (list 1 2 (+ 1 2))
(1 2 3)

For this reason (among others), it is idiomatic clojure to use a vector when describing a literal collection:

user=> [1 2 (+ 1 2)]
[1 2 3]

这篇关于在 Lisp(Clojure、Emacs Lisp)中,list 和 quote 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆