[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Changing tables during traversal: clearing and re-adding a field
- From: Dirk Feytons <dirk.feytons@...>
- Date: Fri, 1 Jul 2011 09:29:05 +0200
On Thu, Jun 30, 2011 at 13:39, Philippe Lhoste <PhiLho@gmx.net> wrote:
> On 29/06/2011 18:15, Dirk Feytons wrote:
>>
>> for k,v in pairs(t) do
>> t[k] = nil
>> if (<some condition>) then
>> t[k] =<some other value>
>> end
>> end
>
> Unless I am missing something (maybe the real code is much more complex),
> you can rewrite it as:
>
> for k, v in pairs(t) do
> if (<some condition>) then
> t[k] = <some other value>
> else
> t[k] = nil
> end
> end
>
> no?
The real code is more complex :)
For the sake of readability it was better to return a new table
instead of modifying the existing one.
--
Dirk