[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: false and nil
- From: dyngeccetor8 <dyngeccetor8@...>
- Date: Tue, 5 Jun 2018 04:35:01 +0300
On 06/04/2018 11:34 PM, Sam Putman wrote:
>> = true and nil
> nil
>[...]
>> = nil and true
> nil
>[...]
>> = false and nil
> false
>
> .. Oh. That's not three-valued logic, then. Well at least
>
>> = nil and false
> nil
>
> That's... not Abelian either.
>
> I would like to propose that a future Lua have `false and nil` yield nil,
> and the same for `nil and false`. This would give an identical semantics
> to the three-valued SQL null[0], and make the trio of values Abelian with
> respect to one another.
Current behavior of "and" and "or" operators is equivalent to
following Lua-like functions.
--[[
"..." means list of remained arguments.
"is_empty(...)" means no arguments.
"process(...)" is some function that will call "f_and" or "f_op"
for remained elements.
]]
f_and =
function(first, ...)
if is_empty(...) then
return first
end
if not first then
return first
else
return process(...)
end
end
f_or =
function(first, ...)
if is_empty(...) then
return first
end
if first then
return first
else
return process(...)
end
end
-- Martin