Is there any difference between closure in Scheme and usual closure in other languages?

僤鯓⒐⒋嵵緔 提交于 2020-01-02 03:53:06

问题


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 enclosed environment variables.

Am I wrong?


回答1:


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.




回答2:


There is a difference in the use of "closure" in SICP from the way it is typically used in computing. From SICP Chapter 2, footnote 6:

The use of the word 'closure' here comes from abstract algebra, where a set of elements is said to be closed under an operation if applying the operation to elements in the set produces an element that is again an element of the set. The Lisp community also (unfortunately) uses the word 'closure' to describe a totally unrelated concept: A closure is an implementation technique for representing procedures with free variables. We do not use the word 'closure' in this second sense in this book.

On the other hand, Schemer's use "closure" to refer to lexical closures just like programmers using other languages with lexical closures.



来源:https://stackoverflow.com/questions/29907801/is-there-any-difference-between-closure-in-scheme-and-usual-closure-in-other-lan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!