lua-users home
lua-l archive

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


I don't think that `nothing` should exist as an entity.

The barrier to understanding is that variable assignment == variable
creation and there is no *real* variable deletion at all. We pretend
things are deleted by reading `nil` and this *mostly* works. Lua tells
us `nil` when we ask for the value of something that never existed. So
*mostly*, setting something that does exist to `nil` is
equivilent-esque.

So forget `nothing`.

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

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

-- Andrew

On Wed, Jul 3, 2013 at 11:20 AM, Sean Conner <sean@conman.org> wrote:
> It was thus said that the Great Sean Conner once stated:
>> It was thus said that the Great Roberto Ierusalimschy once stated:
>> > > Well, I cannot speak for a 'community of best practice' but this is how I
>> > > see the problem. Lua does not have null, as understood in other languages.
>> >
>> > I think it does: it is called 'nil'. What Lua does not have is a way to
>> > store 'nil' in a table.
>>
>>   There are two concepts here, reflected in the following code:
>>
>>       x = function() end
>>       y = function() return nil end
>
>   Some further observations on this topic [1].  Let's flip this around a
> bit.
>
>         function something(mary) --[[ something about mary ]] end
>
>   In straight Lua, there is no way for something to know if it was called
> like:
>
>         something()
>
> or
>
>         something(nil)
>
>   In other words, was something given nothing?  If something was written in
> C, then yes, something can make the distinction between nothing and nil, but
> in Lua, not so much (which is why type can error out with "type()" but not
> with "type(nil)").
>
>   What does the following mean?
>
>         a = function() end
>         b = function() return nothing --[[2]] end
>         c = function() return nil end
>
>   Should nothing only exist in the context of a table entry?  Did the
> previous question even have meaning in the context of language?  How can
> nothing exist, context or no? [3]
>
>   -spc (Or are we all being nihilistic here?)
>
> [1]     Yes, I'm procrastinating at work.  Looking at core files of stripped
>         executables will do that to a person.
>
> [2]     Assuming nothing existed in Lua.
>
> [3]     Okay, *now* I'm being silly.
>
>