如何解释方案表达'(a'b) [英] How to explain scheme expression '(a 'b)

查看:104
本文介绍了如何解释方案表达'(a'b)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(a'b)给出了答案(a'b)。当没有绑定(没有引号)时,这是如何工作的。

解决方案

这是当我们评估表达:

 '(a'b)
=> (a'b)

'引用是 quote 特殊形式,请参阅链接文档以获取更多详细信息:

 (quote(a'b))
=> ; (a'b)

正如您所看到的,它可以防止引用的参数被评估,所以它如果 a 未定义,则无关紧要,因为 a 不会被解释为引用表达式中的变量。这是一个不同的事情,如果我们试图建立一个像这样的列表:

 (list a'b)

code>

以上将产生一个错误,因为 a 是一个未定义的变量,而 b 是一个带引号的表达式。这将工作,因为这两个列表中的元素被引用:

 (list'a'b)
=> (ab)

以下是构建问题中显示的列表的另一种方法:

 (list'a''b)
=> (a'b)


'(a 'b) gives out the answer (a 'b). How does this work when there is no binding for a (which is unquoted).

This is what happens when we evaluate the expression:

'(a 'b)
=> (a 'b)

The ' quote is shorthand for the quote special form, see the linked documentation for more details:

(quote (a 'b))
=> (a 'b)

As you can see, it prevents the quoted arguments from being evaluated, so it doesn't matter if a is undefined, because a is not interpreted as a variable inside a quoted expression. It's a different thing if we tried to build a list like this:

(list a 'b)

The above will produce an error, because a is an undefined variable, whereas b is a quoted expression. This will work, though - because both elements in the list are quoted:

(list 'a 'b)
=> (a b)

And here's another way to build the list shown in the question:

(list 'a ''b)
=> (a 'b)

这篇关于如何解释方案表达'(a'b)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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