本文介绍了Scheme中的闭包和其他语言中的常用闭包之间是否有区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习SICP。我发现SICP中 closure 的定义与其他语言中的闭包定义可能不同(可能)。



以下是SICP所说的内容: p>

这里的闭包在我认为的数学中更接近闭包,而不是我在JavaScript中看到的,这意味着函数访问闭包环境变量的能力。



我错了吗? 你说的对;本文并不是指闭包 - 一种实现策略,以确保函数作为值正确地引用词法绑定 - 但更一般地涉及闭包的数学概念,例如在整数加法操作下关闭。即:将操作应用于集合中的任何两个元素都会产生一个仍然是集合成员的结果。


I'm studying SICP right now. And I found the definition of closure in SICP is (maybe) different from closure definition in other languages.

Here's what SICP says:

Here closure is more close to closure in Mathematics I think, not what I have seen in JavaScript, which means the ability of a function to access enclosure environment variables.

Am I wrong?

解决方案

You're right; this text is not referring to "closures"--an implementation strategy to ensure that functions-as-values refer correctly to lexical bindings--but more generally to the mathematical notion of "closure", as for instance in the statement "the integers are closed under the addition operation". That is: applying the operation to any two elements of the set produces a result that is still a member of the set.

这篇关于Scheme中的闭包和其他语言中的常用闭包之间是否有区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 15:56