[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Undefined variables returning nil
- From: Kevin Martin <kev82@...>
- Date: Tue, 19 Mar 2013 23:29:05 +0000
On 19 Mar 2013, at 22:53, William Sumner wrote:
It was meant as a rhetorical question, to ask yourself. However, to comment on your suggestions:
1) The contains function is clearly a bad idea. How would you implement it?
2) The in operator is better-ish, the first question that comes to mind is how you would modify the C API, as lua_gettable/etc can no longer push nil.
However, I'm just trying to give you things to think about, I'm not interested in engaging in a serious discussion.
If you really want to make this change, you are quite welcome as someone has already said.
I guess my main objection is that I don't actually think there's a problem. I don't see the unsafeness. I also don't think you have explained why it is unsafe, only stated that it is unsafe.
1) nil literally means no-value. Is it not reasonable for a table access to return no-value when there is no value to return?
2) Any attempt to do anything with a nil value yields an error, so if getting the nil value was a mistake as your error is trying to catch, the error will be produced as soon as you try and do anything with the value, see below. Is this so far from you error?
3) Not handling the case of no-value is definitely an error, but that is bad programming, nothing to do with the language.
Kev
-------------------------------------------
> do
>> local x = nil
>> print(x+5)
>> end
stdin:3: attempt to perform arithmetic on local 'x' (a nil value)
stack traceback:
stdin:3: in main chunk
[C]: in ?
>
> do
>> local x = nil
>> x()
>> end
stdin:3: attempt to call local 'x' (a nil value)
stack traceback:
stdin:3: in main chunk
[C]: in ?
>
> do
>> local x = nil
>> print(x.a)
>> end
stdin:3: attempt to index local 'x' (a nil value)
stack traceback:
stdin:3: in main chunk
[C]: in ?
>