[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: continue/repeat...until false dichotomy
- From: "Kelley, Brian" <bkelley@...>
- Date: Tue, 16 Feb 2010 16:25:38 -0800
On Feb 16, 2010, at 3:40 PM, Matthew Wild wrote:
> On 16 February 2010 22:24, Kelley, Brian <bkelley@qualcomm.com> wrote:
>>
>> On Feb 16, 2010, at 1:44 PM, Florian Weimer wrote:
>>
>> Make it:
>>
>> repeat
>> local t = 0
>> if cond then continue end
>> local t = 1
>> ...
>> until t == 0
>>
>> Then the two t are actually different variables (in the current
>> implementation), and it's not clear to which incarnation the
>> comparison refers.
>>
>> Why is it not clear? Would it be clearer without the continue statement?
>> The continue statement does not impact the *scope* of variables. Scoping is
>> lexical -- as written. Continue is just a restricted 'goto'.
>
> If it's so clear, what is the behaviour of the code above?
Assuming "variables default to nil", when 'cond' is true and the continue is taken, "t==0" will evaluate to false because 't' will be nil.
I'm not sure what is throwing you off. Each "local t" declares a new variable. Here is an illustration of that:
local t
local function get() return t end
local t
local function set(a) t = a end
set(2)
print(get()) --> nil
Inserting another "local t" above the continue statement increases the level of confusion -- as shadowing declarations usually do -- but it doesn't have any bearing on the proposed semantics of undefined variables or on how continue interacts with repeat...until.
-bhk