[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Unexpected table.remove behaviour.
- From: lostgallifreyan <lostgallifreyan@...>
- Date: Wed, 24 Jun 2009 21:25:16 +0100
Enrico Colombini <firstname.lastname@example.org> wrote:
>make holes in arrays (use 'false' or a special marker if you need) and
>they won't make holes in your code :-)
Another reason I need to work with holes is this:
Suppose you want to populate a second table while combining a thinning operation on the first, as I described in my last mail. Never mind the issue of whether backwards is faster than forwards when cutting out bits of array, it still helps to work backwards because the table length is changing as you remove stuff, so even if you don't need to sync the second table, you can still run into comparisons or aritmetic attempts on nil values if you work forwards, but not if you work backwards. And as others have said, Lua makes heavy (and powerful) use of 'nil's so they have a habit of populating tables as returns from functions and such. Sometimes it's easier to allow us to over-ride the length value directly, and it allows more flexibility too.