5 ms·
What do you mean by lexically scoped functions? A nested function? My point is that instead of reusing the term closure, one could use the term anonymous funct
by a-nikolaev 6y ago
What do you mean by lexically scoped functions? A nested function?
My point is that instead of reusing the term closure, one could use the term anonymous function. To rephrase my question: Do you have a specific example where a nested function (or an anonymous function) is not lexically scoped (In a language that is otherwise lexically scoped)?
- a-nikolaev 6y agoActually, I know Ruby messes up its functions this way: def f() x = 1 def g() return x end g() end puts f() undefined local variable or method `x' for main:Object (repl):6:in `g' So, the nested function g() cannot capture the scope. I think they had some justification for this funny behavior, because def is not a function, but actually a method (I could be wrong). But in any case, there are examples of languages that don't allow nested functions to capture environment (while a proc or block would capture it).
- codr7 6y agoThey would have to be nested to be in the same scope, so yes. But some languages have nested functions that aren't proper closures. All closures are not anonymous either. The reason we use different terms is because there are subtle differences that are important to capture.