On Mon, Dec 8, 2014 at 3:24 AM, <ele...@gmail.com> wrote: > > > On Monday, December 8, 2014 6:15:37 PM UTC+10, remi....@gmail.com wrote: >> >> Thank you for the explanation Stefan. >> But isn't it possible to just consider the scopes declared inside of a >> function + the global scope while looking for a variable definition? I find >> the fact that the variable can come from the scope in which the function is >> called strange. >> > > It can come from the scope in which the function is defined, not the scope > in which it is called, see > http://docs.julialang.org/en/latest/manual/variables-and-scoping/#scope-of-variables > > Cheers > Lex >
Yes, variables can only come from the scope where the function is defined, not where it is called – that is lexical scoping. Allowing variables to come from the calling scope is dynamic scoping, which has generally fallen out of favor in modern programming languages because it makes it impossible to reason locally about the meaning of code.