lua-users home
lua-l archive

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


On Tue, Mar 13, 2018 at 11:39 PM, Russell Haley <russ.haley@gmail.com> wrote:
>
>
> On Tue, Mar 13, 2018 at 6:45 PM, Coda Highland <chighland@gmail.com> wrote:
>>
>> On Tue, Mar 13, 2018 at 7:47 PM, Tomás Guisasola
>> <tomas@tecgraf.puc-rio.br> wrote:
>> > Hi Roberto
>> >
>> >> No, this is not like JavaScript! 'undef' is NOT a value.
>> >
>> > But it is used as a value.  It sounds strange to me...
>> >
>> >>
>> >> t[i]=undef is a special syntax form that means "remove the key 'i'
>> >> from table 't'".
>> >
>> > But it seems like an assignment.  Wouldn't be better to create a special
>> > syntax for removing a key from a table instead pretending it as an
>> > assingment?
>> >
>> > You should have considered a pair of functions, such as
>> > table.undefine(t, i)
>> > to undefine a key, and table.defined(t, i) to check whether the table
>> > has
>> > the key.  Why did you choose the assignment?
>> >
>> > Regards,
>> > Tomás
>>
>> Functions are a bad idea, because this really is a language primitive.
>
>
> Can I ask why this would be considered a primitive and not just a behaviour
> of tables?
> If it were a function it could be re-assigned and used as a check for any
> bounds value or "tomb stone". It would potentially also be valid in both
> normal and LUA_NILINTABLE mode.
>
> Cheers,
> Russ

Given that tables are the fundamental compound data type of Lua,
there's not a whole lot of distinction. I would consider this to be
akin to rawset, which I also consider to be a primitive operation.
Perhaps it could be superficially a function instead of a keyword, but
it's still effectively a language builtin.

/s/ Adam