Scheme中的闭包和其他语言中的常用闭包之间是否有区别? [英] Is there any difference between closure in Scheme and usual closure in other languages?

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

问题描述

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



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


创建元素对的对的能力是列表结构作为表示工具的重要性的本质。我们将这种能力称为cons的封闭性。通常,如果组合数据对象的操作可以使用相同的操作进行组合,那么组合数据对象的操作就可以满足闭包属性。

这里的闭包在我认为的数学中更接近闭包,而不是我在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:

The ability to create pairs whose elements are pairs is the essence of list structure's importance as a representational tool. We refer to this ability as the closure property of cons. In general, an operation for combining data objects satisfies the closure property if the results of combining things with that operation can themselves be combined using the same operation.

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中的闭包和其他语言中的常用闭包之间是否有区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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