Search code examples
functional-programmingschemeclosuressicp

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


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?


Solution

  • 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.