4 ms·
Actually, I know Ruby messes up its functions this way: def f() x = 1 def g() return x end g() end puts f()
by a-nikolaev 6y ago
Actually, 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).