[julia-users] Re: using statement with for loop inside if statement

2015-12-09 Thread Steven G. Johnson
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. 

Re: [julia-users] Re: using statement with for loop inside if statement

2015-12-09 Thread Isaiah Norton
>
> Something weird/unexpected does seem to be going on here:
>

There are some other edge cases like this where otherwise-top-level
expressions fail (essentially: the lowered code contains a `goto`, which
the interpreter doesn't support. so the thunk is sent to the JIT instead,
which can't yet handle `using`)

see e.g.
https://github.com/JuliaLang/julia/issues/2586
https://github.com/JuliaLang/julia/issues/4893

On Wed, Dec 9, 2015 at 10:50 AM, Josh Langsfeld  wrote:

> 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.
>>
>


[julia-users] Re: using statement with for loop inside if statement

2015-12-09 Thread Brian Rogoff
In what way doesn't it make sense to evaluate it in a local scope? It's 
true that Julia modules don't behave that way now, but other languages 
support local
modules; D and OCaml come to mind.

On Wednesday, December 9, 2015 at 7:22:51 AM UTC-8, 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. 
>


Re: [julia-users] Re: using statement with for loop inside if statement

2015-12-09 Thread Josh Langsfeld
Good to know. I also saw there's another related one where Steven reported 
an almost identical code 
sample: https://github.com/JuliaLang/julia/issues/6901

On Wednesday, December 9, 2015 at 11:03:45 AM UTC-5, Isaiah wrote:
>
> Something weird/unexpected does seem to be going on here:
>>
>
> There are some other edge cases like this where otherwise-top-level 
> expressions fail (essentially: the lowered code contains a `goto`, which 
> the interpreter doesn't support. so the thunk is sent to the JIT instead, 
> which can't yet handle `using`)
>
> see e.g.
> https://github.com/JuliaLang/julia/issues/2586
> https://github.com/JuliaLang/julia/issues/4893
>
> On Wed, Dec 9, 2015 at 10:50 AM, Josh Langsfeld  > wrote:
>
>> 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. 
>>>
>>
>

[julia-users] Re: using statement with for loop inside if statement

2015-12-09 Thread Josh Langsfeld
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. 
>


[julia-users] Re: using statement with for loop inside if statement

2015-12-08 Thread vishesh
ok that also works.
is there some reason that I have to do an explicit eval call? This seems 
like an error at the grammar/parser level of Julia so the eval call just 
exists to make it compile... or so I think?

On Tuesday, December 8, 2015 at 3:53:16 PM UTC-8, Kristoffer Carlsson wrote:
>
> Maybe just @eval the "using" to execute it in global scope