lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I replied to a different thread (too much splitting). To keep things
together, I will cross-post:

I'd suggest not having `nothing`.

        a = function() end
        b = function() return end
        c = function() return nil end

print(select('#', a()), select('#', b()), select('#', c())
--> 0, 0, 1

exists(...)
  return not select('#', ...) == 0
end
local foo
print(exists(foo))
-->true
print(exists(baz))
--false --currently true
print(exists(a()))
--false --currently true
print(exists(b()))
--false --currently true
print(exists(c()))
--true

This is not to suggest an implementation. It is only to illustrate behavior.

-Andrew

On Wed, Jul 3, 2013 at 11:29 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>>   What people seem to be asking for is:
>>
>>       Platonic essence        Lua     NeoLua
>>       nothing                 nil     empty [1]
>>       nil                     nil     nil
>
> How do you distinguish between these two cases?
>
>        x = function() end
>        y = function() return nothing end
>
> -- Roberto
>