I'm sure you have a point in that example. However, I'm getting more 
confused after playing around some more. In repl when I do this:
> foo = 1
> bar() = (foo=foo+1)
> bar()
I get ERROR: foo not defined. So far so good.

But if I write it like this:
> begin
> foo = 1
> bar() = (foo=foo+1)
> bar()
> end
I get 2.

Why wrapping it in block changes the behavior? I thought using a block 
doesn't introduce any new scope, as 
per 
http://julia.readthedocs.org/en/latest/manual/variables-and-scoping/#man-variables-and-scoping.
 
But apparently the bar() inside a block can access foo without declaring it 
global. And outside the block, I can see foo, so apparently it is really a 
global.


On Wednesday, June 11, 2014 11:46:14 AM UTC-4, Stefan Karpinski wrote:
>
> I'm just pointing out that you can't change a global binding without 
> declaring it to be global. That's why I'm confused about what the warning 
> could possibly be for. 
>
>
> On Wed, Jun 11, 2014 at 11:30 AM, Tony Fong <[email protected] 
> <javascript:>> wrote:
>
>> You are assuming perfect knowledge of Julia and with a fresh mind on the 
>> part of the user...
>>
>>
>> On Wednesday, June 11, 2014 11:26:48 AM UTC-4, Stefan Karpinski wrote:
>>
>>> f2 doesn't modify global foo – precisely because it doesn't declare foo 
>>> to be global. So there's nothing to warn about...
>>>
>>>
>>> On Wed, Jun 11, 2014 at 10:58 AM, Tony Fong <
>>> [email protected]> wrote:
>>>
>>>> I'm struggling with something like this:
>>>>
>>>> Module M
>>>>   foo = 1
>>>>   bar()=foo # it's not obvious if foo can be modified. Ok, maybe I 
>>>> should not need a FYI even. 
>>>>   f1()=(global foo=2 ) # this is clear.
>>>>   f2()=(foo = 3 ) # how could I get a warning out of this? it's 
>>>> perfectly legal and may or may not do what the author intends.
>>>> end
>>>>
>>>>  
>>>>
>

Reply via email to