lua-users home
lua-l archive

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


On Sun, Jul 24, 2016 at 5:31 PM, Gavin Wraith <gavin@wra1th.plus.com> wrote:
> In message <CAO40MimhQ7=Zzav4q2Fk4UaF3GRBiahOrsDqt4xEBLtxvyAsKg@mail.gmail.com>
>           Gregg Reynolds <dev@mobileink.com> wrote:
>
>>On Jul 24, 2016 3:27 PM, "Sean Conner" <sean@conman.org> wrote:
>
>>>   Javascript has an "undefined" state, in addition to a "null" state.
>>> Perhaps Lua should have one as well.  To me, "nil" means "the absence of a
>>> value" while "undef" means "this never had a value to begin with".
>
> Is the proposed 'undef' to be assignable? If so, how does its semantics differ
> from 'nil'. If not, does that mean that lengths of tables can never be decreased?
> Is it to be coerced to 'false' in those contexts where 'nil' is coerced to
> false?
>
> Perhaps there should be different 'undefs' according to the circumstances -
> error objects that have state (line number, error message, ... )?

I like this idea, and would suggest the following semantics:

- A variable or table key to which nothing has ever been assigned
would default to 'undef' when a value is requested from it.
- A variable or table key could be effectively deleted by assigning
'undef' to it.
- In defining a sequence, all references to 'nil' would be changed to
'undef', meaning that only 'undef' would create a sequence-terminating
"hole" and 'nil' would no longer terminate a sequence (i.e. '{1, 4, 9,
nil, 25}' would be a valid sequence of length 5).
- 'undef' would join 'nil' and 'false' as falsey values.
- No comment on error *objects* (that should to be a separate
discussion), but there probably should only be one 'undef'. Any more
would probably just cause confusion.

Thoughts?