This is a bit of a follow-up to this question.
- Why is locality determined at compile time and not at execution time? Is it purely for performance?
- Are there languages that look up their variables at execution time? I.e. every time a variable is accessed, this variable is first searched in the local scope and then the search escalates through all enclosing scopes?
- How do ECMA languages handle this?
To put question 2 in other words: Are there languages where the following code (in the necessary syntax) works:
def f(): print ('f')
def g():
f()
f = 42
g()