如何解释方案表达'(a'b) [英] How to explain scheme expression '(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屋!