But an if statement does not introduce new scope, correct?

Something weird/unexpected does seem to be going on here:

julia> VERSION
v"0.5.0-dev+1491"

julia> if true
         using Compat
         println("Using")  
         foreach(println, 1:3)
       end
Using
1
2
3


julia> if true
         using Compat
         println("Using")  
         for i=1:3
           println(i)
         end
       end
ERROR: error compiling anonymous: unsupported or misplaced expression 
"using" in function anonymous
 in eval at ./boot.jl:263



On Wednesday, December 9, 2015 at 10:22:51 AM UTC-5, Steven G. Johnson 
wrote:
>
> A using statement affects the global scope, so it doesn't make a lot of 
> sense to evaluate it in local scope. That's why it's not allowed. The eval 
> function evaluates in global scope, so it can execute a using statement. 
>
> In general, though, if you are eval'ing a using statement, you should 
> probably reorganize your code to do the using directly in global scope. For 
> example, put your code into a module if you want to keep the using 
> statement isolated from other code. 
>

Reply via email to