[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: q: nil in tables
- From: Stephan Hennig <sh-list@...>
- Date: Sun, 18 Mar 2018 12:59:32 +0100
Am 17.03.2018 um 18:54 schrieb Stephan Hennig:
> Am 17.03.2018 um 18:08 schrieb Coda Highland:
>> On Sat, Mar 17, 2018 at 11:55 AM, Stephan Hennig <sh-list@posteo.net> wrote:
>>> Am 17.03.2018 um 17:06 schrieb Stephan Hennig:
>>>
>>>> I tend to think tables with nil are constant size or grow only. So
>>>> here's a stupid question:
>>>>
>> Another realistic example: For performance reasons, you're trying to
>> reuse tables as much as you can. If you need to be able to distinguish
>> between a nil value and an absent key, then you HAVE to be able to
>> properly delete keys if you're going to reuse tables.
>
> A more tough one to discuss away. :-)
>
> For the simple case of finally emptying a table containing nils in
> preparation of reuse, a new function table.empty() can be provided that
> does exactly that.
>
> If single keys had to be removed during lifetime of a table, this
> use-case has the following requirements
>
> a) performance (no metatables if possible),
> b) storing nil in tables,
>
> This certainly required something like undef.
When tables are reused to prevent gc to kick in too often when producing
a fast number of short-lived tables in rapid succession, those tables
are probably of constant size. (Of course, there are still other
reasons for table reuse.)
> It is not quite a common use-case, though, I guess.>
> Thanks for the examples, Coda! May be obvious, but I'd just feel better
> with tables with nils, but without undef.
>
> Best regards,
> Stephan Hennig