[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Nil and false in Lua design
- From: Thomas Jericke <tjericke@...>
- Date: Tue, 15 Oct 2013 05:38:11 +0000
On 10/14/2013 07:16 PM, Sean Conner wrote:
if info.use_extention_a ~= nil and info.use_extension_a then
...
end
if info.use_option_2 ~= nil and info.use_option_2 then
...
end
In other words---it becomes a royal pain in the butt. And for what? A
bit of purity? [2]
Actually you are simply testing for the value "true" here.
if info.use_extention_a == true then
...
end
if info.use_option_2 == true then
...
end
Looks a little strange, because comparing to 'true' is usualy not
necesesarry. But info.use_extention_a could be non boolean so it
actually makes sense. This assumes that equality between different types
is still allowed and returns false if types are different.
There are less theoretical situations where the current implementation
is unintuitive. Mostly the 'or' and 'and' operators. They do not only
accept non boolean values, they also return non-boolean values. typeof(A
or B) could be anything, and 'A' and 'B' don't even have to change their
types for "A or B" to change its type.
typeof(true or 10) -- boolean
typeof(false or 10) -- number
--
Thomas
- References:
- Re: Nil and false in Lua design, Coda Highland
- Re: Nil and false in Lua design, Luiz Henrique de Figueiredo
- Re: Nil and false in Lua design, Thomas Jericke
- Re: Nil and false in Lua design, steve donovan
- Re: Nil and false in Lua design, Dirk Laurie
- Re: Nil and false in Lua design, Carsten Fuchs
- Re: Nil and false in Lua design, Thomas Jericke
- Re: Nil and false in Lua design, steve donovan
- Re: Nil and false in Lua design, Carsten Fuchs
- Re: Nil and false in Lua design, steve donovan
- Re: Nil and false in Lua design, Sean Conner