Hum, this is not exactly the case. I tried this code:

*Input 1:*
workspace()
function foo()
    f = () -> i
    i = 1
    f()
end
foo()
*Output 1:*
1

*Input 2:*
workspace()
function foo()
    f = () -> begin 
        global i
        return i
    end
    i = 1
    f()
end
foo()
*Output 2:*
i not defined.


Even the real implementation is some version similar to what you said, I 
would also like to know how does the compiler treat it exactly.
In C++, for example, with forward declaration, it can *compile*, but it 
won't *links*.

In other words,, during the compilation of Julia, the address of the 
variable "i" is already fixed, or it will look for the real "i" in the 
run-time again?


On Wednesday, March 11, 2015 at 11:35:07 AM UTC+1, Yuuki Soho wrote:
>
> I think Julia implicitly assume that i is a global variable, i.e. your 
> function is equivalent to
>
> f = () -> begin
>     global i
>     return i
> end
>
> So it compiles but throws an error at run-time if i is not defined in the 
> global scope.
>

Reply via email to