为什么Scheme 有list 和quote? [英] Why does Scheme have both list and quote?

查看:52
本文介绍了为什么Scheme 有list 和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?

推荐答案

在您提到的示例中,quotelist 具有相同的结果,因为数字常量对自身求值.如果您在列表中使用不是自我评估的表达式(比如变量或函数调用),您会看到不同之处:

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)) 会给你一个包含符号 abc 的列表> 而 (list abc) 会给你一个列表,其中包含变量 abc 的值(或如果变量不存在则出错).

(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屋!

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