为什么Scheme 有list 和quote? [英] Why does Scheme have both list and quote?
问题描述
既然 (list 1 2 3) 产生 (1 2 3) 和 (quote (1 2 3)) 产生 (1 2 3),那么两者都有的理由是什么?
Since (list 1 2 3) yields (1 2 3) and (quote (1 2 3)) yields (1 2 3), what is the rationale for having both?
由于Scheme 在其他方面如此空闲,所以这些肯定有一些有意义的区别.那是什么?
Since Scheme is otherwise so spare, these must have some meaningful difference. What is that?
推荐答案
在您提到的示例中,quote
和 list
具有相同的结果,因为数字常量对自身求值.如果您在列表中使用不是自我评估的表达式(比如变量或函数调用),您会看到不同之处:
In the example you mentioned quote
and list
have the same result because numeric constants evaluate to themselves. If you use expressions that are not self-evaluating in the list (say variables or function calls), you'll see the difference:
(quote (abc))
会给你一个包含符号 a
、b
和 c
的列表> 而 (list abc)
会给你一个列表,其中包含变量 a
、b
和 c
的值(或如果变量不存在则出错).
(quote (a b c))
will give you a list that contains the symbols a
, b
and c
while (list a b c)
will give you a list containing the values of the variables a
, b
and c
(or an error if the variables do not exist).
这篇关于为什么Scheme 有list 和quote?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!