Dexygen
Dexygen

Reputation: 12561

Shouldn't the definition of closure be more stringent?

I believe I detect ambiguity in the definition of a closure. Specifically it seems as though it would allow the outer scope to be the global scope.

For instance from the wikipedia article at: http://en.wikipedia.org/wiki/Closure_(computer_science)

"A closure (also lexical closure, function closure or function value) is a function together with a referencing environment for the non-local variables of that function."

Specifically non-local could include global variables. Even the article on non local variables at http://en.wikipedia.org/wiki/Non-local_variable states that "the term can refer to global variables". It does go on to qualify matters by stating that globals are not what is usually meant.

Nevertheless, I think we might need to be more stringent in the definition of closures to specifically exclude global variables as the non-local variables. Or is there some case where globals are valid in this context?

EDIT:

Based on comments received and additional thought, to me it seems that there is one specific circumstance where the current definition of closure, ignoring globals, falls short. And that is when the code/function that might otherwise qualify as a closure, can only reference non-local variables that are also global variables

Upvotes: 0

Views: 102

Answers (1)

Dexygen
Dexygen

Reputation: 12561

IMO, yes, see comments above. It may not matter to application developers, but it should matter to compiler/interpreter developers. No sense optimizing something away if you can recognize it in the first place.

Upvotes: 0

Related Questions